📄 frame1.java
字号:
package lookandfeel;import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.borland.jbcl.layout.*;/** * Title: * Description: * Copyright: Copyright (c) 2001 * Company: * @author * @version 1.0 */public class Frame1 extends JFrame { JPanel contentPane; JMenuBar jMenuBar1 = new JMenuBar(); JMenu jMenuFile = new JMenu(); JMenuItem jMenuFileExit = new JMenuItem(); JMenu jMenuHelp = new JMenu(); JMenuItem jMenuHelpAbout = new JMenuItem(); JToolBar jToolBar = new JToolBar(); ImageIcon image1; ImageIcon image2; ImageIcon image3; JLabel statusBar = new JLabel(); JButton jButton1 = new JButton(); JButton jButton2 = new JButton(); JButton jButton3 = new JButton(); JButton jButton4 = new JButton(); JButton jButton5 = new JButton(); XYLayout xYLayout1 = new XYLayout(); JToolBar jToolBar1 = new JToolBar(); JButton jButton6 = new JButton(); JButton jButton7 = new JButton(); JButton jButton8 = new JButton(); /**Construct the frame*/ public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { image1 = new ImageIcon(lookandfeel.Frame1.class.getResource("openFile.gif")); image2 = new ImageIcon(lookandfeel.Frame1.class.getResource("closeFile.gif")); image3 = new ImageIcon(lookandfeel.Frame1.class.getResource("help.gif")); //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(xYLayout1); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); statusBar.setText(" "); jMenuFile.setText("File"); jMenuFileExit.setText("Exit"); jMenuFileExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jMenuFileExit_actionPerformed(e); } }); jMenuHelp.setText("Help"); jMenuHelpAbout.setText("About"); jMenuHelpAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jMenuHelpAbout_actionPerformed(e); } }); jButton1.setText("DemoMetal"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); jButton2.setText("Contrast"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton2_actionPerformed(e); } }); jButton3.setText("Bigcontrast"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton3_actionPerformed(e); } }); jButton4.setText("Lbule"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton4_actionPerformed(e); } }); jButton5.setText("Green"); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton5_actionPerformed(e); } }); jButton6.setText("OldYellow"); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton6_actionPerformed(e); } }); jButton7.setText("Fromtext"); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton7_actionPerformed(e); } }); jButton8.setText("Exit"); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton8_actionPerformed(e); } }); jMenuFile.add(jMenuFileExit); jMenuHelp.add(jMenuHelpAbout); jMenuBar1.add(jMenuFile); jMenuBar1.add(jMenuHelp); this.setJMenuBar(jMenuBar1); contentPane.add(jToolBar, new XYConstraints(0, 0, 400, -1)); jToolBar.add(jButton5, null); jToolBar.add(jButton4, null); jToolBar.add(jButton3, null); jToolBar.add(jButton2, null); jToolBar.add(jButton1, null); contentPane.add(statusBar, new XYConstraints(0, 282, 400, -1)); contentPane.add(jToolBar1, new XYConstraints(3, 32, 400, 34)); jToolBar1.add(jButton6, null); jToolBar1.add(jButton7, null); jToolBar1.add(jButton8, null); } public void showbox() { Frame1_AboutBox box=new Frame1_AboutBox(this); box.show(); box.setLocation(200,200); box.setSize(300,280); box.setModal(true); box.setResizable(true); } /**File | Exit action performed*/ public void jMenuFileExit_actionPerformed(ActionEvent e) { System.exit(0); } /**Help | About action performed*/ public void jMenuHelpAbout_actionPerformed(ActionEvent e) { Frame1_AboutBox dlg = new Frame1_AboutBox(this); Dimension dlgSize = dlg.getPreferredSize(); Dimension frmSize = getSize(); Point loc = getLocation(); dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); dlg.setModal(true); dlg.show(); } /**Overridden so we can exit when window is closed*/ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { jMenuFileExit_actionPerformed(null); } } void jButton5_actionPerformed(ActionEvent e) { try { javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme( new GreenMetalTheme()); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch ( Exception ae ) { ae.printStackTrace(); } showbox(); } void jButton4_actionPerformed(ActionEvent e) { try { javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme( new AquaMetalTheme()); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch ( Exception ae ) { ae.printStackTrace(); } showbox(); } void jButton3_actionPerformed(ActionEvent e) {try { javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme( new BigContrastMetalTheme()); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch ( Exception ae ) { ae.printStackTrace(); } showbox(); } void jButton2_actionPerformed(ActionEvent e) {try { javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme( new ContrastMetalTheme()); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch ( Exception ae ) { ae.printStackTrace(); } showbox(); } void jButton1_actionPerformed(ActionEvent e) {try { javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme( new DemoMetalTheme()); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch ( Exception ae ) { ae.printStackTrace(); } showbox(); } void jButton6_actionPerformed(ActionEvent e) {try { javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme( new KhakiMetalTheme()); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch ( Exception ae ) { ae.printStackTrace(); } showbox(); } void jButton7_actionPerformed(ActionEvent e) {// load a theme from a text file try { PropertiesMetalTheme myTheme = new PropertiesMetalTheme(new FileInputStream("MyTheme.theme")); javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(myTheme); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (IOException ae) { System.out.println(ae); } catch ( Exception ae ) { ae.printStackTrace(); } showbox(); } void jButton8_actionPerformed(ActionEvent e) {System.exit(0); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -