标题:为什么我这个 JInternalFrame 总是跑到 JFrame 外面
只看楼主
littledrop
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-10-28
结帖率:0
已结贴  问题点数:20 回复次数:1 
为什么我这个 JInternalFrame 总是跑到 JFrame 外面
import javax.swing.*;
当我单击“用户管理”的“查询”菜单项目时,弹出的JInternalFrame的窗体总是跑出来,晕了,麻烦帮忙看看。
import java.awt.*;
import java.awt.event.*;

public class JInte extends JFrame implements ActionListener{

    JMenuItem jmi4=new JMenuItem("查询");

    JMenuItem jmi5=new JMenuItem("添加");
    JDesktopPane jd=new JDesktopPane();
    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO 自动生成的方法存根
    if(arg0.getSource()==jmi5)        {
        jd.add(new zhuce());            
        }
        else if(arg0.getSource()==jmi4)
        {
            jd.add(new Text1());
            
            
        }
    }

public JInte()
{
super("主窗体");
JMenuBar jmb=new JMenuBar();
JMenu file=new JMenu("文件");
JMenu file1=new JMenu("用户管理");
JMenuItem jmi1=new JMenuItem("打开");
JMenuItem jmi2=new JMenuItem("保存");
JMenuItem jmi3=new JMenuItem("关闭");

jmi4.addActionListener(this);
jmi5.addActionListener(this);
jmb.add(file);
jmb.add(file1);
file.add(jmi1);
file.add(jmi2);
file.add(jmi3);
file1.add(jmi4);
file1.add(jmi5);
this.setJMenuBar(jmb);
//this.setMenuBar(arg0);
this.setSize(900,700);

//neibu nb=new neibu();
//jd.add(nb);
Container con=this.getContentPane();
con.add(jd);


this.setVisible(true);
}

//public static void main(String s[])
//{
//new JInte();   
//}
}


class neibu extends JInternalFrame
{
    public neibu()
    {
        super("内部窗体");
        this.setSize(200,200);
        this.setResizable(true);
        this.setMaximizable(true);
        this.setClosable(true);
        this.setVisible(true);
            }
}

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

class zhuce extends JInternalFrame implements ActionListener
    {  JTextField t1=new JTextField(10);
       JTextField t2=new JTextField(10);
       JTextField t3=new JTextField(10);
       JTextField t4=new JTextField(10);
       JTextField t5=new JTextField(10);
       JButton b1=new JButton("保存");
       JButton b2=new JButton("退出");
        @Override
        public void actionPerformed(ActionEvent arg0) {
             //TODO Auto-generated method stub
            /*try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection co=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databasename=db_AEIM","sa","123456");
            Statement st=co.createStatement();
            String s1=t1.getText(),s2=t2.getText(),s3=t3.getText(),s4=t4.getText(),s5=t5.getText();
            String s="insert into tb_userlist(userid,username,password,name,department) values('"+s1+"','"+s2+"','"+s3+"','"+s4+"','"+s5+"')";
            int i=st.executeUpdate(s);
            if(i!=0)
                {JOptionPane.showMessageDialog(null,"成功加入!");
            new md();this.dispose();}
            else
                JOptionPane.showMessageDialog(null,"加入失败!");
            }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
            }*/
        
        }
        

        public zhuce()
        {
            super("注册");
            this.setSize(200,400);
            JLabel l=new JLabel("用户名:");
            JLabel l1=new JLabel("昵称:");
            JLabel l2=new JLabel("密码:");
            JLabel l3=new JLabel("姓名:");
            JLabel l4=new JLabel("部门:");
            Container c=this.getContentPane();
            JPanel p=new JPanel();
            b1.addActionListener(this);
            b2.addActionListener(this);
            p.add(l); p.add(t1);p.add(l1);p.add(t2);p.add(l2);p.add(t3);
            p.add(l3);p.add(t4);p.add(l4);p.add(t5);p.add(b1);
            p.add(b2);c.add(p);
            this.setVisible(true);
            }
    }


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.border.*;
import javax.swing.table.*;
import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;

public class Text1 extends JInternalFrame implements ActionListener
{
   
@Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub
      
    if(arg0.getSource()==cha)
        {
        model.setDataVector(null, ta);
        
        /*try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection c=DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;databasename=db_AEIM","sa","123456");
            Statement st=c.createStatement();
            String s1="select * from tb_userlist where userid like '%"+tnum.getText()+"%' and name like '%"+tname.getText()+"%' and department like '%"+cdepartment.getSelectedItem().toString()+"%' and address like '%"+cfrom.getSelectedItem().toString()+"%' and sex like '%"+csex.getSelectedItem().toString()+"%'";
            ResultSet rs=st.executeQuery(s1);
            
            while(rs.next())
            {
                String s[]={rs.getString(1),rs.getString(4),rs.getString(8),rs.getDate(9).toString(),rs.getString(5),rs.getString(7),rs.getString(11),rs.getString(10),
                        rs.getString(14),rs.getString(17),rs.getString(19)};
            model.addRow(s);
               
            }
            }
        catch(Exception e){System.out.println(e.getMessage());}*/
        }
}
JButton cha=new JButton("开始查询");
String ta[]={"员工编号","员工姓名","性别","出生日期","部门","职务","手机号码","籍贯","QQ号码","邮件地址","备注"};
String rows[][]={};
DefaultTableModel model = new DefaultTableModel(rows,ta);
JTable tab=new JTable(model);
JScrollPane scrollPane=new JScrollPane(tab);
JButton ex=new JButton("退出");
JTextField tnum=new JTextField(10);
JTextField tname=new JTextField(10);
String ss[]={"","男","女"};
JComboBox csex=new JComboBox(ss);
JComboBox cfrom=new JComboBox();
JComboBox cdepartment=new JComboBox();
private JFrame f = new JFrame("测试");
private JPanel jp = new JPanel();
private JPanel rjp = new JPanel();
private JPanel bjp = new JPanel();
JButton da=new JButton ("打印信息");



public Text1() {
    super("查询窗体");
    /*try{
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        
        Connection c=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databasename=db_AEIM","sa","123456");
        
        Statement st=c.createStatement();
        ResultSet rs=st.executeQuery("select distinct(address) from tb_userlist");
        cfrom.addItem("");
        cdepartment.addItem("");
        while(rs.next())
        {
            cfrom.addItem(rs.getString(1));
            
        }
        
        ResultSet rs1=st.executeQuery("select distinct(department) from tb_userlist");
        while(rs1.next())
        {
            cdepartment.addItem(rs1.getString(1));
            
        }
    }
    catch(Exception e)
    {
        System.out.println(e.getMessage());
    }*/
ex.addActionListener(this);   
f.setLayout(null);
f.add(jp);
f.add(rjp);
f.add(bjp);
f.add(da);
f.add(ex);
da.setBounds(250,400,80,20);
ex.setBounds(340,400,80,20);
jp.setLayout(null);
rjp.setLayout(null);
bjp.setLayout(null);
JLabel l=new JLabel("请在右边插入查询条件:");
JLabel l1=new JLabel("所有项目均为模糊匹配");
JLabel l2=new JLabel("可以只填写一项或某几项");
l.setBounds(30,10,150,80);
l1.setBounds(30,30,150,80);
l2.setBounds(30,50,150,80);
jp.add(l);
jp.add(l1);
jp.add(l2);
JLabel num=new JLabel("员工编号:");
JLabel sex=new JLabel("性别:");
JLabel name= new JLabel("姓名:");
JLabel from =new JLabel("籍贯:");
JLabel department =new JLabel("部门:");
cha.addActionListener(this);
num.setBounds(10,20,65,20);
tnum.setBounds(80,20,130,20);
sex.setBounds(230,20,40,20);
csex.setBounds(280,20,150,20);
name.setBounds(35,50,65,20);
tname.setBounds(80,50,130,20);
from.setBounds(230,50,40,20);
cfrom.setBounds(280,50,150,20);
department.setBounds(35,80,65,20);
cdepartment.setBounds(80,80,130,20);
cha.setBounds(340,80,90,20);
rjp.add(num);
rjp.add(tnum);
rjp.add(sex);
rjp.add(csex);
rjp.add(name);
rjp.add(tname);
rjp.add(from);
rjp.add(cfrom);
rjp.add(department);
rjp.add(cdepartment);
rjp.add(cha);

scrollPane.setBounds(20,20,620,180);
bjp.add(scrollPane);
f.setBounds(0, 0,700,500);
jp.setBorder(new TitledBorder(new EtchedBorder(), "查询说明"));
jp.setBounds(0, 0, 200, 150);
rjp.setBorder(new TitledBorder(new EtchedBorder(), "查询条件"));
rjp.setBounds(210,0,450,150);
bjp.setBorder(new TitledBorder(new EtchedBorder(), "查询结果"));
bjp.setBounds(0,160,660,220);
f.setVisible(true);
}


public static void main(String[] args) {

JFrame f=new JFrame();
JDesktopPane jd=new JDesktopPane();
jd.add(new Text1());
f.setSize(300,300);
Container c=f.getContentPane();
c.add(jd);
f.setVisible(true);
}

}
搜索更多相关主题的帖子: import public 项目 用户 
2014-06-13 13:28
砖家的谎言
Rank: 12Rank: 12Rank: 12
等 级:禁止访问
威 望:30
帖 子:693
专家分:3898
注 册:2013-12-6
得分:20 
你不想弹出来,在调用的时候关闭这个框框。

我不是砖家,要努力成为砖家。
2014-06-13 14:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-432879-1-1.html




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

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