| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 417 人关注过本帖
标题:为什么不能显示组件
只看楼主 加入收藏
abc888
Rank: 1
等 级:新手上路
威 望:1
帖 子:90
专家分:0
注 册:2007-4-24
收藏
 问题点数:0 回复次数:2 
为什么不能显示组件
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Atmsystem implements ActionListener
{
JFrame frame;
Container con;
JPanel panel1,panel2;
JButton inbutton,okbutton,cancelbutton;
JLabel label1,label2,cardlabel,pwlabel;
Icon bandicon;
Font font,fontpassword;
JTextField card;
JPasswordField password;
String cardnum,paswd;
Atmsystem()
{
frame=new JFrame("ATM System");
frame.setBounds(10,10,500,500);
frame.setVisible(true);
frame.validate();
con=frame.getContentPane();
con.setBackground(Color.BLUE);
con.setVisible(true);
con.validate();


card=new JTextField(15);
password=new JPasswordField(15);
font=new Font("IJ",Font.BOLD,22);
fontpassword=new Font("",Font.BOLD,24);
card.setBounds(200,80,150,30);
password.setBounds(200,160,150,30);
password.setEchoChar('*');
password.setFont(fontpassword);

bandicon=new ImageIcon("logo.gif");
label1=new JLabel("Welcome use the Agriculturl Bank of China",JLabel.CENTER);
label1.setFont(font);
label1.setForeground(Color.YELLOW);
label2=new JLabel(bandicon,JLabel.CENTER);

cardlabel=new JLabel("CardNumber :");
pwlabel=new JLabel("Password :");
cardlabel.setBounds(100,80,90,30);
pwlabel.setBounds(100,160,90,30);
inbutton=new JButton("Plase Insert Your Card");
okbutton=new JButton("OK");
cancelbutton=new JButton("CANCEL");
inbutton.setBounds(150,400,200,30);
okbutton.setBounds(100,400,100,30);
cancelbutton.setBounds(300,400,100,30);
okbutton.addActionListener(this);
cancelbutton.addActionListener(this);
inbutton.addActionListener(this);

panel1=new JPanel();
panel1.setVisible(true);
panel1.setBackground(Color.BLUE);
panel1.setBounds(20,1,450,400);
panel1.add(label1);
panel1.add(label2);
panel1.add(inbutton);
panel1.validate();

panel2=new JPanel();
panel2.setVisible(true);
panel2.setBackground(Color.BLUE);
panel2.setVisible(false);
panel2.setBounds(10,10,450,450);
panel2.add(cardlabel);
panel2.add(pwlabel);
panel2.add(okbutton);
panel2.add(card);
panel2.add(password);
panel2.add(cancelbutton);

con.add(panel1);
con.add(panel2);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==inbutton)
{
panel1.setVisible(false);
panel2.setVisible(true);
}
}
public static void main(String args[])
{
new Atmsystem();
}
}



程序运行后不能正常显示组件帮忙找找原因?
搜索更多相关主题的帖子: 组件 
2007-07-03 23:58
changyawei
Rank: 1
等 级:新手上路
帖 子:87
专家分:0
注 册:2005-11-3
收藏
得分:0 
你把 con.setVisible(true);con.validate();放在con.add(panel1); con.add(panel2)代码的后面试试.


2007-07-04 07:22
食恶不色
Rank: 2
等 级:新手上路
威 望:3
帖 子:632
专家分:5
注 册:2006-11-8
收藏
得分:0 
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.validate();

做人要厚道,看帖要回帖!回帖是尊重,回帖是美德! 美德要发扬,我们要顶帖!顶帖是好事,千万莫灌水!
2007-07-04 08:35
快速回复:为什么不能显示组件
数据加载中...
 
   



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

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