?? dialogexp.java
字號:
/**
* @(#)DialogExp.java
*
*
* @author
* @version 1.00 2007/11/12
*/
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
class MyDialog extends JDialog implements ActionListener {
static final int YES=1,NO=0;
int message=-1;
JButton yes,no;
MyDialog(JFrame f,String s,boolean b) {
super(f,s,b);
yes=new JButton("Yes");
yes.addActionListener(this);
no=new JButton("No");
no.addActionListener(this);
setLayout(new FlowLayout());
add(yes);
add(no);
setBounds(60,60,100,100);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ message=-1;
setVisible(false);
}
}
);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==yes)
{ message=YES;
setVisible(false);
}
else if (e.getSource()==no)
{ message=NO;
setVisible(false);
}
}
public int getMessage()
{ return message;
}
}
class Dwindow extends JFrame implements ActionListener {
JTextArea text;
JButton button;
MyDialog dialog;
Dwindow(String s) {
super(s);
text=new JTextArea(5,22);
button=new JButton("打開對話框");
button.addActionListener(this);
setLayout(new FlowLayout());
add(button);
add(text);
dialog=new MyDialog(this,"我有模式",true);
setBounds(60,60,300,300);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource()==button)
{ dialog.setVisible(true);
if (dialog.getMessage()==MyDialog.YES)
text.append("\n你單擊了對話框的yes按鈕");
else if (dialog.getMessage()==MyDialog.NO)
text.append("\n你單擊了對話框的no按鈕");
else if (dialog.getMessage()==-1)
text.append("\n你單擊了對話框的關閉圖標");
}
}
}
public class DialogExp {
/**
* Creates a new instance of <code>DialogExp</code>.
*/
public DialogExp() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new Dwindow("Window with dialog");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -