📄 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 + -