📄 internaldialog.java
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class InternalDialog implements ActionListener
{
JInternalFrame internalFrame = null;
JLabel label = null;
public InternalDialog()
{
JFrame f = new JFrame("OptionPane Demo");
Container contentPane = f.getContentPane();
JDesktopPane desktopPane = new JDesktopPane();
internalFrame = new JInternalFrame(
"Internal Frame", true,
true,
true,
true);
internalFrame.setLocation( 20,20);
internalFrame.setSize(200,200);
internalFrame.setVisible(true);
Container icontentPane = internalFrame.getContentPane();
JButton b = new JButton("Show Internal Dialog");
b.addActionListener(this);
icontentPane.add(b,BorderLayout.CENTER);
label = new JLabel(" ",JLabel.CENTER);
icontentPane.add(label,BorderLayout.NORTH);
desktopPane.add(internalFrame);
contentPane.add(desktopPane,BorderLayout.CENTER);
f.setSize(350, 350);
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public static void main(String[] args)
{
new InternalDialog();
}
public void actionPerformed(ActionEvent e)
{
String title = "Option Dialog";
String message ="您喜欢吃汉堡吗?";
int messageType = JOptionPane.QUESTION_MESSAGE;
int optionType = JOptionPane.YES_NO_CANCEL_OPTION;
String[] options = {"喜欢","不喜欢","取消"};
int result = JOptionPane.showInternalOptionDialog(internalFrame, message,
title, optionType, messageType,null,options,options[1]);
if (result == JOptionPane.YES_OPTION)
label.setText("您选择:喜欢");
if (result == JOptionPane.NO_OPTION)
label.setText("您选择:不喜欢");
if (result == JOptionPane.CANCEL_OPTION)
label.setText("您选择:取消");
if (result == JOptionPane.CLOSED_OPTION)
label.setText("您没做任何选择,并关闭了对话框");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -