📄 dialogdemo.java
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
class dlg extends Dialog
{
Button bt=new Button("Delete");
dlg(Frame fe,String str)
{
super(fe,str,true);
setLayout(new FlowLayout());
setSize(200,180);
add(bt);
bt.addActionListener(new ko1ActionListener());
}
class ko1ActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
setVisible(false);
}
}
}
public class DialogDemo extends Frame
{
Frame fe;
Menu mu=new Menu("Color");
MenuBar bar=new MenuBar();
MenuItem i1,i2,i3,i4;
public DialogDemo()
{
super("DialogDemo");
setLayout(new FlowLayout());
mu.add(i1=new MenuItem("Red..."));
mu.add(i2=new MenuItem("Green..."));
mu.add(i3=new MenuItem("Blue..."));
mu.add(new MenuItem("-"));
mu.add(i4=new MenuItem("Quit"));
bar.add(mu);
setMenuBar(bar);
setSize(200,180);
setVisible(true);
i1.addActionListener(new ko2ActionListener());
i2.addActionListener(new ko2ActionListener());
i3.addActionListener(new ko2ActionListener());
i4.addActionListener(new ko2ActionListener());
addWindowListener(new koWindowListener());
}
class ko2ActionListener implements ActionListener
{
Frame fe=new Frame();
public void actionPerformed(ActionEvent e)
{
String ko=e.getActionCommand();
if (ko.equals("Red..."))
{
dlg d=new dlg(fe,"Red Dialog Box");
d.setBackground(Color.red);
d.setVisible(true);
}
else if (ko.equals("Green..."))
{
dlg d=new dlg(fe,"Green Dialog Box");
d.setBackground(Color.green);
d.setVisible(true);
}
else if (ko.equals("Blue..."))
{
dlg d=new dlg(fe,"Blue Dialog Box");
d.setBackground(Color.blue);
d.setVisible(true);
}
else if (ko.equals("Quit"))
{
dispose();
System.exit(0);
}
}
}
class koWindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
}
public static void main(String args[])
{
Frame fe=new Frame();
dlg k=new dlg(fe,"The first Dialog");
k.setVisible(true);
DialogDemo ko=new DialogDemo();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -