当前位置: 技术问答>java相关
怎样实现用对话框右上角的*来关掉对话框啊?
来源: 互联网 发布时间:2017-04-11
本文导语: 为什么我编的Dialog类不能象Frame的子类那样可以用窗口右上角的*来关掉窗口啊? 如何实现啊? | 找个例子给你参考: //VoteDialog.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public ...
为什么我编的Dialog类不能象Frame的子类那样可以用窗口右上角的*来关掉窗口啊?
如何实现啊?
如何实现啊?
|
找个例子给你参考:
//VoteDialog.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class VoteDialog extends JPanel {
JLabel label;
JFrame frame;
String simpleDialogDesc = "The candidates";
public VoteDialog(JFrame frame) {
this.frame = frame;
JLabel title;
// Create the components.
JPanel choicePanel = createSimpleDialogBox();
System.out.println("passed createSimpleDialogBox");
title = new JLabel("Click the "Vote" button"
+ " once you have selected a candidate.",
JLabel.CENTER);
label = new JLabel("Vote now!", JLabel.CENTER);
label.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
choicePanel.setBorder(BorderFactory.createEmptyBorder(20,20,5,20));
// Set the layout.
setLayout(new BorderLayout());
add(title, BorderLayout.NORTH);
add(label, BorderLayout.SOUTH);
add(choicePanel, BorderLayout.CENTER);
}
void setLabel(String newText) {
label.setText(newText);
}
private JPanel createSimpleDialogBox() {
final int numButtons = 4;
JRadioButton[] radioButtons = new JRadioButton[numButtons];
final ButtonGroup group = new ButtonGroup();
JButton voteButton = null;
final String defaultMessageCommand = "default";
final String yesNoCommand = "yesno";
final String yeahNahCommand = "yeahnah";
final String yncCommand = "ync";
radioButtons[0] = new JRadioButton("Candidate 1: Sparky the Dog");
radioButtons[0].setActionCommand(defaultMessageCommand);
radioButtons[1] = new JRadioButton("Candidate 2: Shady Sadie");
radioButtons[1].setActionCommand(yesNoCommand);
radioButtons[2] = new JRadioButton("Candidate 3: R.I.P. McDaniels");
radioButtons[2].setActionCommand(yeahNahCommand);
radioButtons[3] = new JRadioButton("Candidate 4: Duke the JavaTM Platform Mascot");
radioButtons[3].setActionCommand(yncCommand);
for (int i = 0; i
//VoteDialog.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class VoteDialog extends JPanel {
JLabel label;
JFrame frame;
String simpleDialogDesc = "The candidates";
public VoteDialog(JFrame frame) {
this.frame = frame;
JLabel title;
// Create the components.
JPanel choicePanel = createSimpleDialogBox();
System.out.println("passed createSimpleDialogBox");
title = new JLabel("Click the "Vote" button"
+ " once you have selected a candidate.",
JLabel.CENTER);
label = new JLabel("Vote now!", JLabel.CENTER);
label.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
choicePanel.setBorder(BorderFactory.createEmptyBorder(20,20,5,20));
// Set the layout.
setLayout(new BorderLayout());
add(title, BorderLayout.NORTH);
add(label, BorderLayout.SOUTH);
add(choicePanel, BorderLayout.CENTER);
}
void setLabel(String newText) {
label.setText(newText);
}
private JPanel createSimpleDialogBox() {
final int numButtons = 4;
JRadioButton[] radioButtons = new JRadioButton[numButtons];
final ButtonGroup group = new ButtonGroup();
JButton voteButton = null;
final String defaultMessageCommand = "default";
final String yesNoCommand = "yesno";
final String yeahNahCommand = "yeahnah";
final String yncCommand = "ync";
radioButtons[0] = new JRadioButton("Candidate 1: Sparky the Dog");
radioButtons[0].setActionCommand(defaultMessageCommand);
radioButtons[1] = new JRadioButton("Candidate 2: Shady Sadie");
radioButtons[1].setActionCommand(yesNoCommand);
radioButtons[2] = new JRadioButton("Candidate 3: R.I.P. McDaniels");
radioButtons[2].setActionCommand(yeahNahCommand);
radioButtons[3] = new JRadioButton("Candidate 4: Duke the JavaTM Platform Mascot");
radioButtons[3].setActionCommand(yncCommand);
for (int i = 0; i