Java Applet Nedir?
Applet örnekleri,applet ve japplet farkı
49,189 Okunma 4 Yorum 05/03/2010 09:49:53
// File : filechooser/CountWords.java
// Purpose: Counts words in file.
// Illustrates menus, JFileChooser, Scanner..
// Author : Fred Swartz
// Date : 2005-02-23, 2005-12-02
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
//////////////////////////////////////////////////////// CountWords
public class CountWords extends JFrame {
//... Instance variables
JTextField m_fileNameTF = new JTextField(15);
JTextField m_wordCountTF = new JTextField(4);
JFileChooser m_fileChooser = new JFileChooser();
//================================================== constructor
CountWords() {
m_fileNameTF.setEditable(false);
m_wordCountTF.setEditable(false);
JButton openButton = new JButton("Open");
//... Add listeners
openButton.addActionListener(new OpenAction());
//... Create contant pane, layout components
JPanel content = new JPanel();
content.setLayout(new FlowLayout());
content.add(openButton);
content.add(m_fileNameTF);
content.add(new JLabel("Word Count"));
content.add(m_wordCountTF);
//... Set window characteristics
this.setTitle("Count Words");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(content);
this.pack();
}
//============================================= countWordsInFile
private int countWordsInFile(File f) {
int numberOfWords = 0; // For counting words.
try {
Scanner wordScanner = new Scanner(f);
wordScanner.useDelimiter("[^A-Za-z]+");
while (wordScanner.hasNext()) {
String word = wordScanner.next();
numberOfWords++;
}
wordScanner.close(); // Close Scanner's file.
} catch (FileNotFoundException fnfex) {
JOptionPane.showMessageDialog(CountWords.this, "You gave me an unreadable file");
}
return numberOfWords;
}
///////////////////////////////////////////////////// OpenAction
class OpenAction implements ActionListener {
public void actionPerformed(ActionEvent ae) {
//... Open a file dialog.
int retval = m_fileChooser.showOpenDialog(CountWords.this);
if (retval == JFileChooser.APPROVE_OPTION) {
//... The user selected a file, process it.
File file = m_fileChooser.getSelectedFile();
//... Update user interface.
m_fileNameTF.setText(file.getName());
m_wordCountTF.setText("" + countWordsInFile(file));
}
}
}
//========================================================= main
public static void main(String[] args) {
JFrame window = new CountWords();
window.setVisible(true);
}
}
Use one of three methods to display the dialog after it has been created.
r = fc.showOpenDialog(owner); // button labeled "Open" r = fc.showSaveDialog(owner); // button labeled "Save" r = fc.showDialog(owner, title);
The owner parameter is the component (eg, JFrame, JPanel, ...) over which the dialog should be centered. You can use null
for the owner, which will put the dialog in the center of the screen. To get the enclosing class's instance, as in this example, write the enclosing class name followed by ".this". The title parameter is a string that is used as the dialog's title and accept button text.
The user may either select a file or directory, or click CANCEL or close the file chooser window. If the user selected a file or directory, the value returned will be JFileChooser.APPROVE_OPTION
. Always check this value. For example,
int retval = fc.showOpenDialog(null); if (retval == JFileChooser.APPROVE_OPTION) { . . . // The user did select a file.;
After checking for JFileChooser.APPROVE_OPTION
, the File
value of the selection is returned from a call on getSelectedFile
.
int retval = fc.showOpenDialog(null);
if (retval == JFileChooser.APPROVE_OPTION) {
File myFile = fc.getSelectedFile();
// DO YOUR PROCESSING HERE. OPEN FILE OR ...
}
Altho a new file chooser can be created inside a listener, there are advantages to creating it once outside and reusing it.
By default a file chooser allows the user to select only files. To allow selection of either files or directories, or only directories, use one of the following calls.
fc.setFileSelectionMode(JFileChooser.FILES_ONLY); // default fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
You can specify the kinds of files that should be shown (eg, with a specific extension, ...), but supplying a JFileFilter
.
myChooser.setFileFilter(FileFilter filter);
See FileFilter. [NEEDS MORE WORK]
The file chooser will start the file dialog at some default directory, for example, "C:My Documents
". To start the dialog at a different directory (called the current directory), specify the directory path as a String
or File
value in the JFileChooser
constructor.
JFileChooser m_fileChooser = new JFileChooser("C:home");
The current directory is ".".
Portability warning: If you put system specific file paths in your code, the program will not be portable to other systems. Note that the above call is therefore not portable.
Kaynak www.roseindia.net/java/java-tips/GUI/containers/20dialogs/30filechooser.shtml
Applet örnekleri,applet ve japplet farkı
49,189 Okunma 4 Yorum 05/03/2010 09:49:53
Java applet nedir?apllet Örnekleri,applet ve japplet farkı
31,531 Okunma 1 Yorum 11/03/2010 08:59:42
Birden fazla resmi yüklemek
31,050 Okunma Henüz yorum yapılmamış 14/06/2010 11:04:09
setLayout(null); setLayout(new FlowLayout()); setLayout(new BorderLayout()); new CardLayout(); Yerleşim Yöneticileri
29,956 Okunma 1 Yorum 26/01/2010 00:09:26 12/04/2017 00:12:53
This document demonstrates how to set up a connection to a MySQL database from NetBeans IDE 6.1. Once connected, you can begin working with MySQL in the IDE's Database Explorer by creating new databases and tables, populating tables with data, and running SQL queries on database structures and content. This tutorial is designed for beginners with a basic understanding of database management, who want to apply their knowledge to working with MySQL in NetBeans IDE.
27,233 Okunma Henüz yorum yapılmamış 16/10/2008 18:48:41
26,526 Okunma Henüz yorum yapılmamış 18/01/2010 21:04:00
Appletlerin temel özellikleri ve kısıtlamalarının aşılması
25,864 Okunma Henüz yorum yapılmamış 03/01/2009 05:42:13
Security manager adlı sistemi sayesinde koda bazı sınırlamalar koyarak kullanıcıya zarar vermesi önlenir. Appletlerdeki bu sınırlamayı aşmanın tek yolu signed applet yaratmaktır
25,393 Okunma Henüz yorum yapılmamış 03/07/2010 17:36:51
Belirli saniye aralıklarla çalışan uygulama
25,032 Okunma 3 Yorum 16/02/2010 21:11:18
Applet kodlarınız kendi makinenizde sorunsuzca çalışıyor ancak webe attığınızda çalışmıyorsa sebebi appletlerin güvenlik sınırlamalarıdır. Bunu aşmak için appleti imzalamalısınız ve kullanıcılarda appletin bilgisayarlarında yapabileceklerini kabul ettiklerinde ancak applet çalışacaktır. Buna Yerel Dosya Sistemine Erişmeye Yetkili Güvenilir Applet yazmakta denebilir.
24,971 Okunma 1 Yorum 04/07/2010 16:19:54
24,483 Okunma Henüz yorum yapılmamış 07/05/2010 10:47:47
Konsolda ve netbeansde ilk program , netbeans proje klasörlerinin anlamları
24,339 Okunma Henüz yorum yapılmamış 20/11/2008 11:50:03
Java classpath tanımlamaları, consolda ilk program yazılması, derlenmesi, çalıştırılması aynı uygulamanın netbeansta yapılışı ve class, java ve jar dosyalarının gösterilmesi
23,943 Okunma Henüz yorum yapılmamış 27/10/2008 14:22:54
Uygulamanın jar dosyasına tıklarsanız ekranın bir görüntüsü önünüze gelecektir.
23,588 Okunma Henüz yorum yapılmamış 12/02/2010 18:56:32
ingilizce bir makale
23,564 Okunma Henüz yorum yapılmamış 06/11/2008 18:18:31
23,138 Okunma Henüz yorum yapılmamış 29/12/2009 03:35:08
Java applet üzerine form nesnelerini eklemek ve etkileşimi sağlamak
22,906 Okunma Henüz yorum yapılmamış 16/01/2009 12:08:34
22,884 Okunma Henüz yorum yapılmamış 13/05/2010 12:37:16
Java swing arayüzlerinden - dosya sistemine erişimi sağlayan JFileChooser sınıfının detayları
22,683 Okunma Henüz yorum yapılmamış 19/07/2010 23:39:20
Tipler ve tip dönüşümünün java uygulaması ile anlatımı
22,513 Okunma Henüz yorum yapılmamış 20/11/2008 13:05:42
Japplet projesinin oluşturulması japplet standart metotları ve metotların görevleri
22,406 Okunma Henüz yorum yapılmamış 18/03/2010 10:46:07
21,985 Okunma Henüz yorum yapılmamış 18/01/2010 21:05:21
21,731 Okunma Henüz yorum yapılmamış 05/03/2010 11:25:29
Java applet üzerine form nesnelerini eklemek
21,542 Okunma Henüz yorum yapılmamış 16/01/2009 12:50:15
20,567 Okunma Henüz yorum yapılmamış 20/11/2008 11:44:50
Bu sayfada jdk indirilmesi ve kurulması - java netbeans 6.1 indirilmesi ve kurulması ile ilgili resimli anlatım dökmanı bulunmaktadır.
19,355 Okunma 1 Yorum 20/10/2008 14:16:22
Basit bir text editör yapımı
19,055 Okunma Henüz yorum yapılmamış 19/01/2010 21:26:06
Basit bir editör yapımı
18,969 Okunma 1 Yorum 19/01/2010 21:19:30
18,742 Okunma 1 Yorum 12/03/2010 11:11:37
18,662 Okunma Henüz yorum yapılmamış 18/01/2010 21:02:35