| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 493 人关注过本帖
标题:java界面运行部出来
只看楼主 加入收藏
wang_7_7
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-3-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
java界面运行部出来
这段代码是一个系统的一部分  运行出来应该是“支出添加”的界面
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class payAdd extends  JInternalFrame implements ActionListener{
      JTextField t1,t2,t3,t4,t5,t6,t7;
      
      JButton bu1,bu2,bu3;
      JComboBox cb;
      JScrollPane sp;
      payInfo a;
      
     payAdd(String s1){
         super(s1);
         t1=new JTextField(3);
         t2=new JTextField(3);
         t3=new JTextField(3);
         t5=new JTextField(3);
         t4=new JTextField(8);
         t6=new JTextField(10);
         t7=new JTextField(10);
     
         Container con1=this.getContentPane();
        con1.setLayout(new BorderLayout());
        JPanel    p1=new JPanel(new FlowLayout());
        JPanel  p2=new JPanel(new FlowLayout());
        ImageIcon img2=new ImageIcon("image/2.jpg");
        JLabel  e3=new JLabel(img2);
        con1.add(e3,BorderLayout.NORTH);
        
        p1.add(new JLabel("日期:"));
        p1.add(new JLabel("年"));
        p1.add(t1);
        p1.add(new JLabel("月"));
        p1.add(t2);
        p1.add(new JLabel("日"));
        p1.add(t3);
        p1.add(new JLabel("序号"));
        p1.add(t5);
        
        p1.add(new JLabel("物品:"));
        p1.add(t4);
        
        String[] s={"学习类","饮食类","服装类","日常用品类","其他"};
        
        cb=new JComboBox(s);
        cb.setEditable(true);
        p1.add(new JLabel("类型:"));
        p1.add(cb);
   
        
        p1.add(new JLabel("金额:"));
        p1.add(t6);
        
        p1.add(new JLabel("备注:"));
        p1.add(t7);
   
        p1.setBackground(Color.decode("#F6E3DD"));
        con1.add(p1,BorderLayout.CENTER);
        
        bu1=new JButton("保存并添加");
        bu1.setBackground(Color.decode("#F6E3DD"));
        bu1.setFont(new Font("Dialog",0,12));
        bu2=new JButton("保存并关闭");
        bu2.setBackground(Color.decode("#F6E3DD"));
        bu2.setFont(new Font("Dialog",0,12));
        bu3=new JButton("退出");
        bu3.setBackground(Color.decode("#F6E3DD"));
        bu3.setFont(new Font("Dialog",0,12));
        
        bu1.addActionListener(this);
        bu2.addActionListener(this);
        bu3.addActionListener(this);
        
        
                                                                                          
        p2.add(bu1,BorderLayout.CENTER);
        p2.add(bu2);
        p2.add(bu3);
        p2.setBackground(Color.decode("#F6E3DD"));
        con1.add(p2,BorderLayout.SOUTH);
        setBounds(350,290,345,265);
        setVisible(true);
        setResizable(false);
          setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          setIconifiable(true);
        setClosable(true);
        setResizable(true);
        setMaximizable(true);

     }
     
 public void actionPerformed(ActionEvent e){
     if(e.getSource()==bu1){
         try{
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Connection conn=DriverManager.getConnection("jdbc:odbc:money");
          Statement stat = conn.createStatement();
                                                            
          stat.executeUpdate("insert into 支出单 values('"+t1.getText()+""+t2.getText()+""+t3.getText()+"-"+t5.getText()+"','"+t1.getText()+"-"+t2.getText()+"-"+t3.getText()+"','"+t4.getText()+"','"+cb.getSelectedItem()+"','"+t6.getText()+"','"+t7.getText()+"')");
           
           stat.close();
           this.dispose();
           
           payAdd a=new payAdd("支出添加");
           
         
         }catch (Exception ex) {
               System.err.println("异常:"+ex.getMessage());
          }
     }   
     else if(e.getSource()==bu2){
         try{
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Connection conn=DriverManager.getConnection("jdbc:odbc:money");
          Statement stat = conn.createStatement();
                                                            
          stat.executeUpdate("insert into 支出单 values('"+t1.getText()+""+t2.getText()+""+t3.getText()+"-"+t5.getText()+"','"+t1.getText()+"-"+t2.getText()+"-"+t3.getText()+"','"+t4.getText()+"','"+cb.getSelectedItem()+"','"+t6.getText()+"','"+t7.getText()+"')");
           
           stat.close();
           this.dispose();
           
         
         }catch (Exception ex) {
               System.err.println("异常:"+ex.getMessage());
          }
     }   
     else if(e.getSource()==bu3){
         this.dispose();
         
     }
 }
  public static void main(String[] atgs){
    new payAdd("12");
}
}

搜索更多相关主题的帖子: java 运行部 界面 
2010-06-01 14:57
linjx0123
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:279
专家分:1362
注 册:2006-4-7
收藏
得分:20 
public static void main(String[] atgs){
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(400,300);
      payAdd p = new payAdd("12");
      frame.setContentPane(p);
      frame.setVisible(true);
}

JInternalFrame是不可以单独显示的
2010-06-02 10:00
童磊
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-6-3
收藏
得分:0 
?????????????????????????????????????????????????
2010-06-03 23:16
快速回复:java界面运行部出来
数据加载中...
 
   



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

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