Frame with Menus , Dialog , Panels arranged in BorderLayout
import java.awt.*;
import java.awt.event.*;
/*class WindowDemo extends Window {
WindowDemo(Frame myf)
{ super(myf);
setSize(200,100);
setVisible(true);
setBackground(Color.red);
}
}*/
public class TestFrameWindow extends Frame implements ActionListener {
private Button btclose,btok;
private Panel pes, pws,pnr, psu,pce;
private Font myf;
private List mylist ;
private TextArea ta;
private Dialog dlg;
private MenuBar mb;
private Menu filem, editm, helpm, workspace;
private MenuItem exitmi, openmi, openallmi;
TestFrameWindow() {
mb = new MenuBar();
setMenuBar(mb);
filem = new Menu("File");
editm = new Menu("Edit");
helpm = new Menu("Help");
workspace = new Menu("WorkSpace..");
mb.add(filem);
mb.add(editm); mb.add(helpm);
exitmi = new MenuItem("Exit");
MenuShortcut shrtct = new MenuShortcut(KeyEvent.VK_X,true);
exitmi.setShortcut(shrtct);
exitmi.addActionListener(this);
filem.add(workspace);
filem.add(exitmi);
openmi = new MenuItem("Open ");
openallmi = new MenuItem("Open All");
workspace.add(openmi); workspace.add(openallmi);
//dialog creation
dlg = new Dialog(this);
dlg.setSize(200,100);
dlg.setTitle("DialogExample");
dlg.add(new Button("OK ...."));
pes = new Panel(); pes.setBackground(Color.red);
pnr = new Panel(); pnr.setBackground(Color.cyan);
psu = new Panel(); psu.setBackground(Color.magenta);
pce = new Panel(); pce.setBackground(Color.green);
pws = new Panel(); pws.setBackground(Color.blue);
btclose = new Button("CLOSE");
myf = new Font("SERIF",Font.BOLD + Font.ITALIC,21);
btclose.setFont(myf);
btok = new Button("OK");
btok.setBackground(Color.gray);
btok.setForeground(Color.yellow);
Dimension mydim = new Dimension(60,60);
btok.setPreferredSize(mydim);
btok.addActionListener(this);
btclose.addActionListener(this);
mylist = new List();
mylist.add("c:");
mylist.add("d:");
mylist.add("e:");
ta = new TextArea(100,60);
add(pes, BorderLayout.EAST);
add(pws , BorderLayout.WEST);
add(pnr, BorderLayout.NORTH);
add(pce , BorderLayout.CENTER);
add(psu, BorderLayout.SOUTH);
psu.add(btclose);
pnr.add(btok);
pws.add(mylist);
pce.add(ta);
//new WindowDemo(this);
//new Window(this).setVisible(true);
setTitle("Frame example");
setSize(400,500);
setBackground(Color.lightGray);
setVisible(true);
setExtendedState(Frame.MAXIMIZED_BOTH);
}
public void actionPerformed(ActionEvent ae ) {
if (ae.getSource().equals(btok) )
{
dlg.setVisible(true);
}
else if (ae.getSource().equals(btclose) )
{
dlg.setVisible(false);
}
if(ae.getSource().equals(exitmi))
{
System.exit(0);
}
}
public static void main(String args[] ) {
new TestFrameWindow();
}
}
import java.awt.event.*;
/*class WindowDemo extends Window {
WindowDemo(Frame myf)
{ super(myf);
setSize(200,100);
setVisible(true);
setBackground(Color.red);
}
}*/
public class TestFrameWindow extends Frame implements ActionListener {
private Button btclose,btok;
private Panel pes, pws,pnr, psu,pce;
private Font myf;
private List mylist ;
private TextArea ta;
private Dialog dlg;
private MenuBar mb;
private Menu filem, editm, helpm, workspace;
private MenuItem exitmi, openmi, openallmi;
TestFrameWindow() {
mb = new MenuBar();
setMenuBar(mb);
filem = new Menu("File");
editm = new Menu("Edit");
helpm = new Menu("Help");
workspace = new Menu("WorkSpace..");
mb.add(filem);
mb.add(editm); mb.add(helpm);
exitmi = new MenuItem("Exit");
MenuShortcut shrtct = new MenuShortcut(KeyEvent.VK_X,true);
exitmi.setShortcut(shrtct);
exitmi.addActionListener(this);
filem.add(workspace);
filem.add(exitmi);
openmi = new MenuItem("Open ");
openallmi = new MenuItem("Open All");
workspace.add(openmi); workspace.add(openallmi);
//dialog creation
dlg = new Dialog(this);
dlg.setSize(200,100);
dlg.setTitle("DialogExample");
dlg.add(new Button("OK ...."));
pes = new Panel(); pes.setBackground(Color.red);
pnr = new Panel(); pnr.setBackground(Color.cyan);
psu = new Panel(); psu.setBackground(Color.magenta);
pce = new Panel(); pce.setBackground(Color.green);
pws = new Panel(); pws.setBackground(Color.blue);
btclose = new Button("CLOSE");
myf = new Font("SERIF",Font.BOLD + Font.ITALIC,21);
btclose.setFont(myf);
btok = new Button("OK");
btok.setBackground(Color.gray);
btok.setForeground(Color.yellow);
Dimension mydim = new Dimension(60,60);
btok.setPreferredSize(mydim);
btok.addActionListener(this);
btclose.addActionListener(this);
mylist = new List();
mylist.add("c:");
mylist.add("d:");
mylist.add("e:");
ta = new TextArea(100,60);
add(pes, BorderLayout.EAST);
add(pws , BorderLayout.WEST);
add(pnr, BorderLayout.NORTH);
add(pce , BorderLayout.CENTER);
add(psu, BorderLayout.SOUTH);
psu.add(btclose);
pnr.add(btok);
pws.add(mylist);
pce.add(ta);
//new WindowDemo(this);
//new Window(this).setVisible(true);
setTitle("Frame example");
setSize(400,500);
setBackground(Color.lightGray);
setVisible(true);
setExtendedState(Frame.MAXIMIZED_BOTH);
}
public void actionPerformed(ActionEvent ae ) {
if (ae.getSource().equals(btok) )
{
dlg.setVisible(true);
}
else if (ae.getSource().equals(btclose) )
{
dlg.setVisible(false);
}
if(ae.getSource().equals(exitmi))
{
System.exit(0);
}
}
public static void main(String args[] ) {
new TestFrameWindow();
}
}
Comments
Post a Comment