java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Dialog
java.awt.FileDialog
- All Implemented Interfaces:
- ImageObserver, MenuContainer, Serializable, Accessible
- See Also:
- Top Examples, Source Code,
Window.show()
public void addNotify()
- See Also:
Container.removeNotify()
, Component.isDisplayable()
, Dialog
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public FileDialog(Dialog parent)
- See Also:
GraphicsEnvironment.isHeadless()
, IllegalArgumentException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public FileDialog(Dialog parent,
String title)
- See Also:
GraphicsEnvironment.isHeadless()
, IllegalArgumentException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public FileDialog(Dialog parent,
String title,
int mode)
- See Also:
SAVE
, LOAD
, GraphicsEnvironment.isHeadless()
, IllegalArgumentException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public FileDialog(Frame parent)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public FileDialog(Frame parent,
String title)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public FileDialog(Frame parent,
String title,
int mode)
- See Also:
SAVE
, LOAD
, IllegalArgumentException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[65]Use FileDialog
By Anonymous on 2005/06/22 06:23:15 Rate
// Opens a file
public void load ( ) {
Frame frame = new Frame ( ) ;
FileDialog fd = new FileDialog ( frame, "KickJava.com", FileDialog.LOAD ) ;
fd.show ( ) ;
String filename = fd.getFile ( ) ;
File f = new File ( filename ) ;
int size = ( int ) f.length ( ) ;
int bytes_read = 0;
if ( filename != null ) {
try {
FileInputStream fis = new FileInputStream ( filename ) ;
byte [ ] data = new byte [ size ] ;
while ( bytes_read < size )
bytes_read += fis.read ( data, bytes_read, size-bytes_read ) ;
this.setText ( new String ( data ) ) ;
}
catch ( Exception e ) {
System.out.println ( e ) ;
}
}
}
public String getDirectory()
- See Also:
setDirectory(java.lang.String)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public String getFile()
- See Also:
setFile(java.lang.String)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public FilenameFilter getFilenameFilter()
- See Also:
setFilenameFilter(java.io.FilenameFilter)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int getMode()
- See Also:
setMode(int)
, SAVE
, LOAD
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int LOAD
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected String paramString()
- See Also:
- Dialog
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static final int SAVE
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1068]Simple Notepad SWING application
By kishorerajukk { at } yahoo { dot } com on 2004/10/25 03:39:58 Rate
import java.awt.*;
import java.io.*;
import java.awt.event.*;
public class notepad1 extends Frame implements ActionListener
{
TextArea ta;
MenuBar mb;
Menu mfile,medit,msearch,mhelp;
new1 new2;
MapFileDialog mapfile;
public notepad1 ( )
{
setTitle ( "NotePad" ) ;
setLocation ( 30,50 ) ;
setSize ( 730,440 ) ;
setBackground ( Color.lightGray ) ;
ta=new TextArea ( ) ;
ta.setBounds ( 10,10,700,400 ) ;
mb=new MenuBar ( ) ;
setMenuBar ( mb ) ;
mfile=new Menu ( "File" ) ;//file menu
MenuItem f1=new MenuItem ( "New" ) ;
mfile.add ( f1 ) ;
MenuItem f2=new MenuItem ( "Open" ) ;
mfile.add ( f2 ) ;
MenuItem f3=new MenuItem ( "Save" ) ;
mfile.add ( f3 ) ;
MenuItem f4=new MenuItem ( "Close" ) ;
mfile.add ( f4 ) ;
MenuItem f5=new MenuItem ( "Closeall" ) ;
mfile.add ( f5 ) ;
medit=new Menu ( "Edit" ) ;//Edit menu
MenuItem e1=new MenuItem ( "Undo" ) ;
medit.add ( e1 ) ;//edit's child
MenuItem e2=new MenuItem ( "Copy" ) ;
medit.add ( e2 ) ;//edit's child
MenuItem e3=new MenuItem ( "Paste" ) ;
medit.add ( e3 ) ;//edit's child
MenuItem e4=new MenuItem ( "Cut" ) ;
medit.add ( e4 ) ;//edit's child
msearch=new Menu ( "Search" ) ;
mhelp=new Menu ( "Help" ) ;
add ( ta ) ;
mb.add ( mfile ) ;
mb.add ( medit ) ;
mb.add ( msearch ) ;
mb.add ( mhelp ) ;
mfile.addActionListener ( this ) ;
addWindowListener ( new WindowAdapter ( ) {
public void windowClosing ( WindowEvent we ) {
setVisible ( false ) ;
dispose ( ) ;
}
} ) ;
}
public void actionPerformed ( ActionEvent ae )
{
String s=ae.getActionCommand ( ) ;
if ( s.equals ( "New" ) )
{
if ( new2!=null )
{
new2.setVisible ( true ) ;
}
else
{
new2=new new1 ( ) ;
new2.show ( ) ;
}
}
if ( s.equals ( "Open" ) )
{
fOpen ( ) ;
// mapfile=new MapFileDialog ( ) ;
}
if ( s.equals ( "Save" ) )
{
fSave ( ) ;
// mapfile=new MapFileDialog ( ) ;
}
if ( s.equals ( "Close" ) )
{
dispose ( ) ;
System.exit ( 0 ) ;
}
}
public void fOpen ( )
{
FileDialog fd = new FileDialog ( new Frame ( ) ,
"Open file...", FileDialog.LOAD ) ;
fd.show ( ) ;
if ( fd.getFile ( ) != null )
{
String path=fd.getDirectory ( ) + fd.getFile ( ) ;
try
{
FileInputStream fr=new FileInputStream ( path ) ;
BufferedInputStream br=new BufferedInputStream ( fr ) ;
int str;
while ( ( str=br.read ( ) ) !=-1 )
{
char c= ( char ) str;
String s=""+c;
ta.append ( s ) ;
}
}
catch ( Exception e )
{
System.out.println ( e ) ;
}
System.out.println ( fd.getDirectory ( ) + fd.getFile ( ) ) ;
}
else
System.out.println ( "Open cancelled!" ) ;
}
public void fSave ( )
{
FileDialog fd = new FileDialog ( new Frame ( ) ,
"Open file...", FileDialog.SAVE ) ;
fd.show ( ) ;
if ( fd.getFile ( ) != null )
{
String st=fd.getFile ( ) ;
//System.out.println ( st ) ;
// FileReader fr=new FileReader ( st )
try
{
FileWriter fw=new FileWriter ( st ) ;
BufferedWriter br=new BufferedWriter ( fw ) ;
//String st=ta.getText ( ) ;
while ( ! ( st.equals ( null ) ) )
{
//char c= ( char ) sr;
// int i=Integer.parseInt ( sr ) ;
br.write ( st ) ;
}
br.close ( ) ;
fr.close ( ) ;
}
catch ( Exception e )
{
System.out.println ( e ) ;
}
System.out.println ( fd.getDirectory ( ) + fd.getFile ( ) ) ;
}
else
System.out.println ( "Open cancelled!" ) ;
}
public static void main ( String args [ ] ) throws Exception
{
notepad1 no=new notepad1 ( ) ;
no.show ( ) ;
}
}
public void setDirectory(String dir)
- See Also:
getDirectory()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1697]Noepad
By mleczyk { at } nofate { dot } com on 2006/01/12 03:03:44 Rate
//Ex_no_16
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.text.DefaultEditorKit;
public class Ex_no_16 extends Frame implements WindowListener, ActionListener
{
JTextArea jta = new JTextArea ( ) ;
public Ex_no_16 ( )
{
super ( ) ;
addWindowListener ( this ) ;
setSize ( 400, 400 ) ;
setTitle ( "Notatnik" ) ;
MenuBar menuBar = new MenuBar ( ) ;
setMenuBar ( menuBar ) ;
Menu menu = new Menu ( "Plik" ) ;
menu.add ( new MenuItem ( "New" ) ) ;
menu.add ( new MenuItem ( "Open" ) ) ;
menu.add ( new MenuItem ( "Save" ) ) ;
menu.add ( new MenuItem ( "Zamknij" ) ) ;
Menu menu_2 = new Menu ( "Edit" ) ;
menu_2.add ( new MenuItem ( "Copy" ) ) ;
menu_2.add ( new MenuItem ( "Cut" ) ) ;
menu_2.add ( new MenuItem ( "Paste" ) ) ;
menu_2.add ( new MenuItem ( "SelectAll" ) ) ;
// ten wpis w konstruktorze oznacza, ze chcemy reagowac na zdarzenia zwiazane
// z obiektem menu
menu.addActionListener ( this ) ;
menuBar.add ( menu ) ;
menu_2.addActionListener ( this ) ;
menuBar.add ( menu_2 ) ;
//JTextFiled
JScrollPane jsp = new JScrollPane ( jta ) ;
jta.setEditable ( true ) ;
jta.setSize ( 10, 10 ) ;
jta.setVisible ( true ) ;
this.add ( jsp ) ;
setVisible ( true ) ;
}
public static void main ( String args [ ] ) {
new Ex_no_16 ( ) ;
}
public void actionPerformed ( ActionEvent e ) {
// ActionEvent - pozwala na stwierdzenie jakiego typu zdarzenie zaszlo
// getActionCommand zwraca napis ( String )
if ( e.getActionCommand ( ) == "Zamknij" ) {
System.exit ( 0 ) ;
}
if ( e.getActionCommand ( ) == "New" ) {
try {
jta.getDocument ( ) .remove ( 0, jta.getDocument ( ) .getLength ( ) ) ;
} catch ( Exception ee ) {
System.err.println ( "Blad New Option: " + ee ) ;
}
}
if ( e.getActionCommand ( ) == "Cut" ) {
jta.cut ( ) ;
}
if ( e.getActionCommand ( ) == "Copy" ) {
jta.copy ( ) ;
}
if ( e.getActionCommand ( ) == "Paste" ) {
jta.paste ( ) ;
}
if ( e.getActionCommand ( ) == "SelectAll" ) {
jta.selectAll ( ) ;
}
if ( e.getActionCommand ( ) == "Open" ) {
fOpen ( ) ;
}
if ( e.getActionCommand ( ) == "Save" ) {
fSave ( ) ;
}
}
public void fOpen ( )
{
FileDialog fd = new FileDialog ( new Frame ( ) , "Open file...", FileDialog.LOAD ) ;
fd.setFile ( "*.txt" ) ;
fd.show ( ) ;
if ( fd.getFile ( ) != null ) {
String path=fd.getDirectory ( ) + fd.getFile ( ) ;
try {
FileInputStream fr=new FileInputStream ( path ) ;
BufferedInputStream br=new BufferedInputStream ( fr ) ;
DefaultEditorKit dek = new DefaultEditorKit ( ) ;
dek.read ( br, jta.getDocument ( ) , 0 ) ;
} catch ( Exception e ) {
System.err.println ( "Error: " +e ) ;
}
System.out.println ( fd.getDirectory ( ) + fd.getFile ( ) ) ;
} else
System.out.println ( "Open cancelled!" ) ;
}
public void fSave ( ) {
FileDialog fd = new FileDialog ( new Frame ( ) , "Save file...", FileDialog.SAVE ) ;
fd.setFile ( "*.txt" ) ;
fd.show ( ) ;
if ( fd.getDirectory ( ) != null )
if ( fd.getFile ( ) != null ) {
String stt =fd.getDirectory ( ) ;
String st = fd.getFile ( ) ;
try {
FileWriter fw = new FileWriter ( stt + st ) ;
BufferedWriter br =new BufferedWriter ( fw ) ;
DefaultEditorKit dek = new DefaultEditorKit ( ) ;
dek.write ( br, jta.getDocument ( ) , 0,jta.getDocument ( ) .getLength ( ) ) ;
fw.close ( ) ;
}
catch ( Exception e ) {
System.err.println ( "Error: " +e ) ;
}
System.out.println ( fd.getDirectory ( ) + fd.getFile ( ) ) ;
} else
System.out.println ( "Save cancelled !" ) ;
}
public void windowClosing ( WindowEvent e ) {
System.exit ( 0 ) ;
}
public void windowClosed ( WindowEvent e ) {
}
public void windowOpened ( WindowEvent e ) {
}
public void windowIconified ( WindowEvent e ) {
}
public void windowDeiconified ( WindowEvent e ) {
}
public void windowActivated ( WindowEvent e ) {
}
public void windowDeactivated ( WindowEvent e ) {
}
}
public void setFile(String file)
- See Also:
getFile()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void setFilenameFilter(FilenameFilter filter)
- See Also:
getFilenameFilter()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1149]FilenameFilter
By Anonymous on 2005/04/26 06:30:19 Rate
FilenameFilter exstensies = new FilenameFilter ( "*.txt,*.doc,*.c*,-*.cnt" ) ;
public void setMode(int mode)
- See Also:
getMode()
, SAVE
, LOAD
, IllegalArgumentException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples