publicJMenugetJMenu2(Stringtit1){JMenujmu=newJMenu();jmu.setText(tit1);jmit2=getJMenuItem("查询");jmit2.addActionListener(newActionListener(){publicvoidactionPerformed(Ac...
public JMenu getJMenu2(String tit1){
JMenu jmu = new JMenu();
jmu.setText(tit1);
jmit2 = getJMenuItem("查询");
jmit2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Statement stmt = null;
ResultSet rs = null;
String[] colHeads={"编 号","账 号","密 码","性 别","学 历","Email","Q Q","生 日"};
//窗体
JFrame jf = new JFrame();
//面板
JPanel jpl = new JPanel();
jpl.setLayout(null); //设置布局方式为自定义
int i=0;
Object[][] base = new Object[1][9];
try {
Sqlsever data = new Sqlsever();//连接数据库
con = data.getDatabase(con);
stmt = con.createStatement();
rs=stmt.executeQuery("select * from member");
while(rs.next()){
base[i][0] = rs.getInt("memID");
base[i][1] = rs.getString("memNum");
base[i][2] = rs.getString("memPsw");
base[i][3] = rs.getString("memSex");
base[i][4] = rs.getString("memSch");
base[i][5] = rs.getString("memLike");
base[i][6] = rs.getString("memEmail");
base[i][7] = rs.getInt("memQQ");
base[i][8] = rs.getDate("memBtday");
i++;
}
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
}
JTable table = new JTable(base,colHeads);
JScrollPane jsp=new JScrollPane(table);
getContentPane().add(jsp);
table.setPreferredScrollableViewportSize(new Dimension(500, 400));
getContentPane().add(jsp, BorderLayout.NORTH);
//背景图片
JLabel pitLabel1=new JLabel(new ImageIcon("images/bg1.jpg"));
pitLabel1.setBounds(0, -10, 600, 500);
jpl.add(pitLabel1);
jf.setSize(600,500);
jf.setResizable(false); //设置窗体大小不可变
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setIconImage(new ImageIcon("images/icon.gif").getImage());
jf.setContentPane(table);
jf.setContentPane(jpl);
jf.setVisible(true);
}
});
我这是我写的代码,我想达到的效果是,点击菜单栏的“查询”,就弹出一个新的窗体显示出数据库中的数据!但是现在新的窗体中显示不出数据库中的内容!
请高手帮忙解决!
展开