1.you write an appication not applet, start() will not be automatically called.
2.JFrame frame is never add to your application, so nothing shows.
2.JFrame frame is never add to your application, so nothing shows.
p.show();
import java.awt.*;
import java.awt.event.*;
public class CutAndCat extends JFrame implements ItemListener
{
boolean inAnApplet = true;
JPanel cards;
String comboBoxItems[] = { " 分割 ", " 合并 "};
//JFrame frame=new JFrame("分割&合并");
JPanel cbp = new JPanel(); public CutAndCat(){
super("分割&合并");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComboBox c = new JComboBox(comboBoxItems);
c.setEditable(false);
c.addItemListener(this);
cbp.add(c); //Use the default layout manager, BorderLayout
getContentPane().add(cbp, BorderLayout.NORTH); cards = new JPanel();
cards.setLayout(new CardLayout());
cards.add(new PanelForCut(), " 分割 ");
cards.add(new PanelForCat(), " 合并 ");
getContentPane().add(cards,BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (inAnApplet) {
dispose();
} else {
System.exit(0);
}
}
});
pack();
setVisible(true);
}
public void itemStateChanged(ItemEvent evt) {
CardLayout cl = (CardLayout)(cards.getLayout());
cl.show(cards, (String)evt.getItem());
} public static void main(String args[])
{
try {
Font font=new Font("",Font.PLAIN,12);
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIManager.put("Label.font",font);
UIManager.put("Button.font",font);
UIManager.put("TabbedPane.font",font);
UIManager.put("FileChooser.font",font);
}
catch (Exception e) { }
CutAndCat p=new CutAndCat();
}
}