import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class databank{
public static void main(String args[ ]){
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.println(""+e);
}
DatabaseWin win=new DatabaseWin();
}
}
class DatabaseWin extends JFrame implements ActionListener{//主窗口
JMenuBar menubar;
JMenu menuC,menuO,menuW,menuS;
JMenuItem itemCShow,itemCInUp,
itemOShow,itemOInUp,
itemWShow,itemWInUp,
itemSShow,itemSInUp;
Panel centerPanel;
CardLayout card;
DatabaseWin(){
setBackground(Color.BLUE);
centerPanel=new Panel();
card=new CardLayout();
centerPanel.setLayout(card);
ClientShow clientShow = new ClientShow();
ClientInsertUpdate clientInsertUpdate = new ClientInsertUpdate();
centerPanel.add("clientShow",clientShow);
centerPanel.add("clientInsertUpdate",clientInsertUpdate);
menubar=new JMenuBar();
menuC=new JMenu("顾客");
menuO=new JMenu("订单");
menuW=new JMenu("生产厂家");
menuS=new JMenu("库存商品");
itemCShow=new JMenuItem("显示");
itemCInUp=new JMenuItem("更新及插入");
itemOShow=new JMenuItem("显示");
itemOInUp=new JMenuItem("更新及插入");
itemWShow=new JMenuItem("显示");
itemWInUp=new JMenuItem("更新及插入");
itemSShow=new JMenuItem("显示");
itemSInUp=new JMenuItem("更新及插入");
itemCShow.addActionListener(this);
itemCInUp.addActionListener(this);
itemOShow.addActionListener(this);
itemOInUp.addActionListener(this);
itemWShow.addActionListener(this);
itemWInUp.addActionListener(this);
itemSShow.addActionListener(this);
itemSInUp.addActionListener(this);
menuC.add(itemCShow);
menuC.add(itemCInUp);
menuO.add(itemOShow);
menuO.add(itemOInUp);
menuW.add(itemWShow);
menuW.add(itemWInUp);
menuS.add(itemSShow);
menuS.add(itemSInUp);
menubar.add(menuC);
menubar.add(menuO);
menubar.add(menuW);
menubar.add(menuS);
setJMenuBar(menubar);
setBounds(100,200,650,300);
setVisible(true);
add(centerPanel,BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==itemCShow){
card.show(centerPanel,"clientShow");
}
else if(e.getSource()==itemCInUp){
card.show(centerPanel, "clientInsertUpdate");
}
else if(e.getSource()==itemOShow){
}
else if(e.getSource()==itemOInUp){
}
else if(e.getSource()==itemWShow){
}
else if(e.getSource()==itemWInUp){
}
else if(e.getSource()==itemSShow){
}
else if(e.getSource()==itemSInUp){
};
}
}ClientShow.java 文件可以自己写一个,如果大家需要我会贴出ClientShow的代码。
此时菜单就会被PANEL给挡住,可是改变下窗口大小后就菜单就能显示正常了,请问解决办法是什么
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class databank{
public static void main(String args[ ]){
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
System.out.println(""+e);
}
DatabaseWin win=new DatabaseWin();
}
}
class DatabaseWin extends JFrame implements ActionListener{//主窗口
JMenuBar menubar;
JMenu menuC,menuO,menuW,menuS;
JMenuItem itemCShow,itemCInUp,
itemOShow,itemOInUp,
itemWShow,itemWInUp,
itemSShow,itemSInUp;
Panel centerPanel;
CardLayout card;
DatabaseWin(){
setBackground(Color.BLUE);
centerPanel=new Panel();
card=new CardLayout();
centerPanel.setLayout(card);
ClientShow clientShow = new ClientShow();
ClientInsertUpdate clientInsertUpdate = new ClientInsertUpdate();
centerPanel.add("clientShow",clientShow);
centerPanel.add("clientInsertUpdate",clientInsertUpdate);
menubar=new JMenuBar();
menuC=new JMenu("顾客");
menuO=new JMenu("订单");
menuW=new JMenu("生产厂家");
menuS=new JMenu("库存商品");
itemCShow=new JMenuItem("显示");
itemCInUp=new JMenuItem("更新及插入");
itemOShow=new JMenuItem("显示");
itemOInUp=new JMenuItem("更新及插入");
itemWShow=new JMenuItem("显示");
itemWInUp=new JMenuItem("更新及插入");
itemSShow=new JMenuItem("显示");
itemSInUp=new JMenuItem("更新及插入");
itemCShow.addActionListener(this);
itemCInUp.addActionListener(this);
itemOShow.addActionListener(this);
itemOInUp.addActionListener(this);
itemWShow.addActionListener(this);
itemWInUp.addActionListener(this);
itemSShow.addActionListener(this);
itemSInUp.addActionListener(this);
menuC.add(itemCShow);
menuC.add(itemCInUp);
menuO.add(itemOShow);
menuO.add(itemOInUp);
menuW.add(itemWShow);
menuW.add(itemWInUp);
menuS.add(itemSShow);
menuS.add(itemSInUp);
menubar.add(menuC);
menubar.add(menuO);
menubar.add(menuW);
menubar.add(menuS);
setJMenuBar(menubar);
setBounds(100,200,650,300);
setVisible(true);
add(centerPanel,BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==itemCShow){
card.show(centerPanel,"clientShow");
}
else if(e.getSource()==itemCInUp){
card.show(centerPanel, "clientInsertUpdate");
}
else if(e.getSource()==itemOShow){
}
else if(e.getSource()==itemOInUp){
}
else if(e.getSource()==itemWShow){
}
else if(e.getSource()==itemWInUp){
}
else if(e.getSource()==itemSShow){
}
else if(e.getSource()==itemSInUp){
};
}
}ClientShow.java 文件可以自己写一个,如果大家需要我会贴出ClientShow的代码。
此时菜单就会被PANEL给挡住,可是改变下窗口大小后就菜单就能显示正常了,请问解决办法是什么
在界面中要么全是Swing的组件,要么全用AWT的组件,不要混着用。