[求助]为什么编译成功却不能显示
import java.awt.*;import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class DialogDemo extends JFrame implements ActionListener{
JButton b1=new JButton("信息提示对话框(只有'ok'按纽)");
JButton b2=new JButton("确认对话框(有'yes/no'两个按纽)");
JButton b3=new JButton("选项对话框(有'yes/no'两个按纽,附加文字,有图标)");
JButton b4=new JButton("输入对话框(带选择的)");
JButton b5=new JButton("输入对话框(输入的)");
JLabel LL=new JLabel();
public void DialogDemo(){
Container contentPane=getContentPane();
contentPane.setLayout(new GridLayout(6,1));
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
contentPane.add(b1);contentPane.add(b2);
contentPane.add(b3);contentPane.add(b4);
contentPane.add(b5);contentPane.add(LL);
setTitle("对话框演示");
setSize(300,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
JOptionPane.showMessageDialog(null,"JAVA世界丰富多采");
}
if(e.getSource()==b2){
int n=JOptionPane.showConfirmDialog(
null,
"你喜欢JAVA吗?",
"问题对话框",
JOptionPane.YES_NO_OPTION);
if(n==JOptionPane.YES_OPTION)
LL.setText("你喜欢,我也是");
else if(n==JOptionPane.NO_OPTION)
LL.setText("你不喜欢,可是我喜欢");
else
LL.setText("请告诉我吧!");
}
else if(e.getSource()==b3){
Object options[]={"是的","不喜欢"};
int n=JOptionPane.showOptionDialog(
null,
"你喜欢JAVA吗?",
"问题对话框",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
if(n==JOptionPane.YES_OPTION)
LL.setText("你喜欢,我也是");
else if(n==JOptionPane.NO_OPTION)
LL.setText("你不喜欢,可是我喜欢");
else
LL.setText("请告诉我吧!");
}
else if(e.getSource()==b4){
ImageIcon icon=new ImageIcon("11.gif");
Object[] possibilities={"C++","VB","JAVA"};
String s=(String)JOptionPane.showInputDialog(
null,
"请选择项目:\n欢喜哪种语言?",
"客户选择",
JOptionPane.PLAIN_MESSAGE,
icon,
possibilities,
"JAVA");
if((s!=null)&&(s.length()>0)){
LL.setText("你喜欢"+s+"语言!");
return;
}
else
LL.setText("希望你选择!");
}
else if(e.getSource()==b5){
ImageIcon icon=new ImageIcon("11.gif");
Object[] possibilities={"C++","VB","JAVA"};
String s=(String)JOptionPane.showInputDialog(
null,
"请选择项目:\n欢喜哪种语言?",
"客户选择",
JOptionPane.PLAIN_MESSAGE,
icon,
possibilities,
"JAVA");
if((s!=null)&&(s.length()>0)){
LL.setText("你喜欢"+s+"语言!");
return;
}
else
LL.setText("希望你选择!");
}
}
public static void main(String args[]){
JFrame.setDefaultLookAndFeelDecorated(true);
Font font=new Font("JFrame",Font.PLAIN,14);
Enumeration keys=UIManager.getLookAndFeelDefaults().keys();
while(keys.hasMoreElements()){
Object key=keys.nextElement();
if(UIManager.get(key) instanceof Font)
UIManager.put(key,font);
}
DialogDemo mainFrame=new DialogDemo();
}
}
请问大侠:为什么可以编译成功,却不能显示??