| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 615 人关注过本帖
标题:[求助]为什么编译成功却不能显示
只看楼主 加入收藏
xinghun868
Rank: 1
等 级:新手上路
帖 子:62
专家分:0
注 册:2007-6-1
收藏
 问题点数:0 回复次数:2 
[求助]为什么编译成功却不能显示
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();
}
}



请问大侠:为什么可以编译成功,却不能显示??
搜索更多相关主题的帖子: JButton 对话框 import new 
2007-09-07 00:23
george_vcool
Rank: 2
等 级:新手上路
威 望:3
帖 子:453
专家分:0
注 册:2007-7-23
收藏
得分:0 

你的构造方法中多了一个void,构造方法应该是没有返回类型的!!

2007-09-07 00:54
xinghun868
Rank: 1
等 级:新手上路
帖 子:62
专家分:0
注 册:2007-6-1
收藏
得分:0 

原来是这样啊~~谢谢


2007-09-11 10:21
快速回复:[求助]为什么编译成功却不能显示
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014848 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved