| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1076 人关注过本帖
标题:javaGUI设计中,JFrame的连接
只看楼主 加入收藏
dydsdyds
Rank: 6Rank: 6
来 自:Java
等 级:侠之大者
帖 子:217
专家分:457
注 册:2010-2-14
结帖率:81.82%
收藏
 问题点数:0 回复次数:1 
javaGUI设计中,JFrame的连接
这次学期末的课程设计,需要用GUI设计一个取款机的小程序,
现在遇到了几个问题,
我做了好几个界面,怎么链接起来?
我用JFrame做的,能不能加上图片背景?
我附一段代码。
程序代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Welcome extends JFrame
{
       private JComboBox jcb;
       private JPanel p1,p2;
       private JLabel pic;
       private JButton ok,cancel;
       private JLabel name,psw,note;
       private JPasswordField pswf;

       private String name1;
       private String password1;
       private String user;

       private ImageIcon myImage;

       public Welcome( )
       {             

    Container contentPane = getContentPane();
          contentPane.setLayout(new BorderLayout() );
         
          pic=new JLabel(new ImageIcon("欢迎界面.jpg"));
             contentPane.add(pic,BorderLayout.NORTH);
            
   
    p1= new JPanel();
    //p1.setSize(50,50);
          p1.setBorder(BorderFactory.createEtchedBorder() );       //显示一圈边儿
    contentPane.add(p1,BorderLayout.CENTER );

     name=new JLabel("请输入卡号");
             p1.add(name);
          jcb= new JComboBox();
          jcb.addItem( "admin" );
          jcb.addItem( "aloie" );
          jcb.setSelectedIndex( 0 );
          jcb.setEditable(true);
          p1.add(jcb);
     
          psw=new JLabel("请输入密码");
    p1.add(psw);            
             pswf=new JPasswordField(12);
             p1.add(pswf);

    p2=new JPanel();
    contentPane.add(p2,BorderLayout.SOUTH);
    contentPane.add(p2,BorderLayout.SOUTH );
     ok=new JButton("登  陆");
     ok.addActionListener(
                new ActionListener()
          {
                public void actionPerformed(ActionEvent event)
                 {
                       okJButtonActionPerformed(event);
                 }
          }
          );
     cancel=new JButton("取  消");
     cancel.addActionListener(
         new ActionListener()
         {
            public void actionPerformed( ActionEvent event )
            {
               System.exit(0);        //退出登陆
            }

         }
      );
            note=new JLabel("如有疑问请联系客服热线12580");
          p2.add(ok);
          p2.add(cancel);
          p2.add(note);

         
                  

          setTitle( "登陆窗口" ); 
          this.pack();
          setResizable( false );           //将最大化按钮设置为不可用
          show();
   }

    private void okJButtonActionPerformed( ActionEvent event )
   {
      //okJButton响应事件,检查用户名和密码的匹配
         name1= jcb.getSelectedItem().toString();
         if (name1.equals("admin") )
         {         
                if (pswf.getText().equals("admin"))
                {
                       showNewWindow();
                       setVisible( false);
                } else
             {
                            JOptionPane.showMessageDialog( this,"密码错误,拒绝登陆",
                            "密码错误 !", JOptionPane.ERROR_MESSAGE );
                }
         }
         else if (name1.equals("aloie"))
         {
                if ( pswf.getText().equals("aloie") )
                {
                        showNewWindow();
                    setVisible(false);
                }
                else
                {
                            JOptionPane.showMessageDialog( this,"密码错误,拒绝登陆",
                   "密码错误 !", JOptionPane.ERROR_MESSAGE );
                }
         }
   }

       public void showNewWindow()
       {
              Goangneng();
       }

    public static void main(String[] args )
   {   
               //JFrame.setDefaultLookAndFeelDecorated(true);
               Welcome mylogin = new Welcome( );
               mylogin.setVisible( true );
               mylogin.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );  
   }
}

第二个
程序代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Gongneng extends JFrame
{
       private JComboBox nameJComboBox;
       private JPanel userJPanel,buttonPanel;
       private JLabel pictureJLabel;
       private JButton okJButton,cancelJButton,gmJButton,qkJButton;
       private JLabel nameJLabel,passwordJLabel,note;
       private JPasswordField passwordJPasswordField;

       private String name1;
       private String password1;
       private String user;

       private ImageIcon myImageIcon;

       public Gongneng( )
       {             

    Container contentPane = getContentPane();
          contentPane.setLayout(new BorderLayout() );
         
          pictureJLabel=new JLabel();
          pictureJLabel.setIcon(new ImageIcon("pic.jpg"));
             contentPane.add(pictureJLabel,BorderLayout.NORTH);
            
   
    userJPanel = new JPanel();
    userJPanel.setSize(50,50);
          userJPanel.setBorder(BorderFactory.createEtchedBorder() );       //显示一圈边儿
    contentPane.add(userJPanel,BorderLayout.CENTER );

    

    buttonPanel=new JPanel();
    buttonPanel.setSize(400,400);
    contentPane.add(buttonPanel,BorderLayout.SOUTH );
     okJButton=new JButton("查询");
     cancelJButton=new JButton("取款");
    gmJButton=new JButton("改密 ");
     qkJButton=new JButton("取卡");
          note=new JLabel("");
          buttonPanel.add(okJButton);
          buttonPanel.add(cancelJButton);
          buttonPanel.add(gmJButton);
          buttonPanel.add(qkJButton);
          buttonPanel.add(note);

          setTitle( "功能窗口" ); 
          this.pack();
          setSize(350, 350 );
          setResizable( true );           //将最大化按钮设置为不可用
   }

    public static void main( String[] args )
   {   
               Gongneng mylogin = new Gongneng( );
               mylogin.setVisible( true );
               mylogin.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );  
   }
}
但是,我连不起来这两个窗口。
谢谢
搜索更多相关主题的帖子: JFrame javaGUI 设计 
2010-12-09 09:53
dydsdyds
Rank: 6Rank: 6
来 自:Java
等 级:侠之大者
帖 子:217
专家分:457
注 册:2010-2-14
收藏
得分:0 
就是怎么将两个窗体链接在一块

c语言刚开一学期,就换开VB...
2010-12-09 17:32
快速回复:javaGUI设计中,JFrame的连接
数据加载中...
 
   



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

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