show官方标配

展开阅读全文

show

11-06

我编了一程序, javac 通过了产生 .class文件后,写了html文件,但是程序运行后有错误.请大家看看.我的mail:huo3078@sohu.comrn//html文件rn////////////////////////////////////////////////rnrnrnrn PrintShop rnrn rnrnrnrnrn rnrnrnrnrn rnrnrn///////////////////////////////////rnrn//java文件rn// Example Java program to show some Swing ideas in practicernrn// First, import our swing packages (and the AWT stuff we usually need)rnimport javax.swing.*;rnimport javax.swing.event.*;rnimport java.awt.*;rnimport java.awt.event.*;rnrnpublic class SwingExample implements ActionListenerrnrn // declare variablesrn static JPanel contentPane;rn static JMenuBar menuBar;rn static JMenu fileMenu;rn JMenuItem menuItem;rn JButton helloButton;rn JButton goodbyeButton; rn JLabel label;rn BorderLayout borderLayout;rnrn public SwingExample()rn rn // set up menu barrn menuBar = new JMenuBar();rn menuBar.setLayout(new BoxLayout(menuBar, BoxLayout.X_AXIS));rn fileMenu = new JMenu("File");rn menuBar.add(fileMenu);rn menuItem = new JMenuItem("Exit");rn menuItem.setActionCommand("Exit");rn menuItem.addActionListener(this);rn fileMenu.add(menuItem);rn // set up labelrn label = new JLabel("Hello");rn label.setHorizontalAlignment(JLabel.CENTER);rnrn // set up buttonsrn helloButton = new JButton("Hello");rn helloButton.setActionCommand("Hi");rn helloButton.addActionListener(this);rnrn goodbyeButton = new JButton("Goodbye");rn goodbyeButton.setActionCommand("Bye");rn goodbyeButton.addActionListener(this);rnrn //set up layoutrn borderLayout = new BorderLayout();rn borderLayout.setHgap(5);rn borderLayout.setVgap(10);rnrn // create content panern contentPane = new JPanel();rn contentPane.setLayout(borderLayout);rn contentPane.add(label, BorderLayout.NORTH);rn contentPane.add(helloButton, BorderLayout.EAST);rn contentPane.add(goodbyeButton, BorderLayout.WEST);rn // end constructorrnrn public void actionPerformed(ActionEvent e)rn rn if ((e.getActionCommand()).equals("Exit"))rn rn System.exit(0);rn rn else if ((e.getActionCommand()).equals("Hi"))rn rn label.setText("Hello");rn rn else if ((e.getActionCommand()).equals("Bye"))rn rn label.setText("Goodbye");rn rn // end actionPerformedrnrn public static void main(String[] args)rn rn JFrame frame = new JFrame("Swing Example");rn SwingExample example = new SwingExample();rnrn frame.setJMenuBar(menuBar);rn frame.setContentPane(contentPane);rn frame.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); );rn frame.pack();rn frame.setVisible(true);rn // end mainrn // end class Swing examplernrn 论坛

没有更多推荐了,返回首页