Skip to main content

File Dialog In AWT

File Dialog:
import java.awt.*;
import java.awt.event.*;
public class DialogApplication extends Frame implements ActionListener, WindowListener
{
Button l,s;
TextField tf;
public static void main(String s[])
{
DialogApplication da=new DialogApplication();
da.setVisible(true);
da.setSize(200,200);
}
DialogApplication()
{
super("Dialog Application");
setLayout(new FlowLayout());
l=new Button("Load");
l.addActionListener(this);
add(l);
s=new Button("Save");
s.addActionListener(this);
add(s);
tf=new TextField(20);
add(tf);
addWindowListener(this);
}
public void actionPerformed(ActionEvent ae)
{
FileDialog fd;
if (ae.getSource() == l)
{
fd=new FileDialog(this, "FileDialog",FileDialog.LOAD);
}
else
{
fd=new FileDialog(this, "FileDialog",FileDialog.SAVE);
}
fd.show();
String filename=fd.getFile();
if(filename!=null)
{
tf.setText(filename);
}
}
public void windowActivated(WindowEvent we){}
public void windowClosed(WindowEvent we){}
public void windowClosing(WindowEvent we){System.exit(0);}
public void windowDeactivated(WindowEvent we){}
public void windowDeiconified(WindowEvent we){}
public void windowIconified(WindowEvent we){}
public void windowOpened(WindowEvent we){}     }

Comments

Popular posts from this blog

16 to 20 Java questions

16. How do you set security in applets? using setSecurityManager() method 17. What is a layout manager and what are different types of layout managers available in java AWT? A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout 18. What is JDBC? JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications. 19. What are drivers available? a) JDBC-ODBC Bridge driver b) Native API Partly-Java driver c) JDBC-Net Pure Java driver d) Native-Protocol Pure Java driver 20. What is stored procedure? Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task. Stored Procedures are used to encapsulate a set of operations or queries to execute on database. Stored procedures can be compiled and...

Latest Java 11 to 15

11. What are the states associated in the thread? Thread contains ready, running, waiting and dead states. 12. What is synchronization? Synchronization is the mechanism that ensures that only one thread is accessed the resources at a time. 13. What is deadlock? When two threads are waiting each other and can’t precede the program is said to be deadlock. 14. What is an applet? Applet is a dynamic and interactive program that runs inside a web page displayed by a java capable browser 15. What is the lifecycle of an applet? init() method – Can be called when an applet is first loaded start() method – Can be called each time an applet is started. paint() method – Can be called when the applet is minimized or maximized. stop() method – Can be used when the browser moves off the applet’s page. destroy() method – Can be called when the browser is finished with the applet.

What is Servet ?

A servlet is a java class that extends an application hosted on a web server. Handles the HTTP request-response process (for our purposes) Often thought of as an applet that runs on a server. Provides a component base architecture for web development, using the Java Platform The foundation for Java Server Pages (JSP). Alternative to CGI scripting and platform specific server side applications.