📄 testb.java
字号:
import java.awt.*;
import java.awt.event.*;
public class testB
{
public static void main(String args[])
{
MyDialogFrame df=new MyDialogFrame();
}
}
class MyDialogFrame extends Frame implements ActionListener,ComponentListener,FocusListener
{
Dialog Meg,Inout;
Button btn1,btn2,btnY,btnN,btnR;
TextField tf=new TextField("无信息",45);
TextField getMeg=new TextField("输入信息",10);
MyDialogFrame()
{
super("使用对话框");
btn1=new Button("隐藏");
btn2=new Button("询问");
btnY=new Button("是");
btnN=new Button("否");
btnR=new Button("返回");
setLayout(new FlowLayout());
add(tf);
add(btn1);
add(btn2);
btn1.addComponentListener(this);
this.addWindowListener(new WinAdpt());
btn1.addActionListener(this);
btn2.addActionListener(this);
btnY.addActionListener(this);
btnN.addActionListener(this);
btnR.addActionListener(this);
setSize(350,150);
show();
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="隐藏")
{
Meg=new Dialog(this,"真的要隐藏吗?",true);
Panel p1=new Panel();
p1.add(new Label("此操作将隐藏按钮,继续吗?"));
Meg.add("Center",p1);
Panel p2=new Panel();
p2.add(btnY);
p2.add(btnN);
Meg.add("South",p2);
Meg.setSize(200,100);
Meg.show();
}
else if(e.getActionCommand()=="询问")
{
Inout=new Dialog(this,"请输入信息");
Inout.add("Center",getMeg);
Inout.add("South",btnR);
Inout.setSize(200,100);
Inout.addFocusListener(this);
Inout.show();
}
else if(e.getActionCommand()=="是")
{
Meg.dispose();
btn1.setVisible(false);
}
else if(e.getActionCommand()=="否")
Meg.dispose();
else if(e.getActionCommand()=="返回")
{
tf.setText(getMeg.getText()+"是对话框的输入");
Inout.dispose();
}
}
public void componentShown(ComponentEvent e){}
public void componentResized(ComponentEvent e){}
public void componentMoved(ComponentEvent e){}
public void componentHidden(ComponentEvent e)
{
tf.setText("按钮\""+((Button)e.getComponent()).getLable()+"\"被隐藏!");
}
public void focusGained(FocusEvent e)
{
getMeg.setText("对话框\""+((Dialog)e.getComponent()).getTitle()+"\"获得了注意的焦点!");
}
public void focusLost(FocusEvent e){}
}
class WinAdpt extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
((Frame)e.getWindow()).dispose();
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -