?? jdialogtest.java
字號:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class JDialogTest extends JApplet{
JPanel jPanel1= new JPanel();
JPanel jPanel2 = new JPanel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
GridLayout gridLayout1 = new GridLayout();
JFrame jframe1=new JFrame();
JDialog jdialog1 = new JDialog(jframe1, "JDialog示范一", true);
JButton okButton = new JButton("確定"),
applyButton = new JButton("應用"),
cancelButton = new JButton("取消");
JButton[] diaButtons = new JButton[] {
okButton, applyButton, cancelButton,
};
JDialog jdialog2 = new JDialog(jframe1, "JDialog示范二", false);
//初始化
public void init() {
try {
myInit();
}
catch(Exception e) { //異常處理
e.printStackTrace();
}
}
//組件初始設定
private void myInit() throws Exception {
this.setSize(new Dimension(300, 150));
this.getContentPane ().setLayout(new BorderLayout(5,5));
jButton1.setText("JDialog示范一");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setText("JDialog示范二");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jPanel2.setLayout(gridLayout1);
gridLayout1.setColumns(1);
gridLayout1.setHgap(5);
gridLayout1.setRows(2);
gridLayout1.setVgap(5);
this.getContentPane().add(jPanel2, BorderLayout.CENTER);
jPanel2.add(jButton1, null);
jPanel2.add(jButton2, null);
for(int i=0; i < diaButtons.length; ++i) {
jPanel1.add(diaButtons[i]);
}
jdialog1.setSize(150,100);
jdialog2.getContentPane().add(jPanel1);
}
void jButton1_actionPerformed(ActionEvent e) {
jdialog1.setVisible(true);
}
void jButton2_actionPerformed(ActionEvent e) {
jdialog2.pack();//將對話框大小壓成組件所占的偏好大小
jdialog2.setVisible(true);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -