⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frame1.java~20~

📁 用java编写的一个小的swing例程
💻 JAVA~20~
字号:
package netadm;

import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
//import javax.swing.UIManager;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.Box;
import javax.swing.JList;
import javax.swing.JEditorPane;
import com.borland.jbcl.layout.*;
import javax.swing.JCheckBox;
import javax.swing.JProgressBar;
import javax.swing.JTree;
import javax.swing.*;
import java.awt.Toolkit;
import java.awt.Dimension;

/**
 * <p>Title: tetle</p>
 *
 * <p>Description: amo</p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: lee</p>
 *
 * @author among
 * @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();
  ImageIcon image1 = new ImageIcon(netadm.Frame1.class.getResource(
      "openFile.png"));
  ImageIcon image2 = new ImageIcon(netadm.Frame1.class.getResource(
      "closeFile.png"));
  ImageIcon image3 = new ImageIcon(netadm.Frame1.class.getResource("help.png"));
  JMenuItem jMenuItem1 = new JMenuItem();
  JMenu jMenu1 = new JMenu();
  JMenuBar jMenuBar2 = new JMenuBar();
  JMenuItem jMenuItem2 = new JMenuItem();
  FlowLayout flowLayout1 = new FlowLayout();
  JPanel jPanel1 = new JPanel();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  public Frame1()
  {

    Toolkit thekit=();


    try
    {
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      jbInit();
    }
    catch (Exception exception)
    {
      exception.printStackTrace();
    }
  }

  /**
   * Component initialization.
   *
   * @throws java.lang.Exception
   */
  private void jbInit() throws Exception
  {
    contentPane = (JPanel) getContentPane();
    contentPane.setLayout(flowLayout1);
    this.getContentPane().setBackground(Color.pink);
    setSize(new Dimension(353, 300));
    setTitle("Netdesign");
    jMenuFile.setText("File");
    jMenuFileExit.setText("Exit");
    jMenuFileExit.addActionListener(new Frame1_jMenuFileExit_ActionAdapter(this));
    jMenuHelp.setText("Help");
    jMenuHelpAbout.setText("About");
    jMenuHelpAbout.addActionListener(new Frame1_jMenuHelpAbout_ActionAdapter(this));
    jMenuItem1.setText("open");
    jMenu1.setText("edit");
    jMenuItem2.setText("haoren");
    contentPane.setBackground(new Color(255, 249, 158));
    jButton1.setHorizontalAlignment(SwingConstants.LEFT);
    jButton1.setText("jButton1");
    jButton1.setVerticalAlignment(SwingConstants.TOP);
    jButton1.setVerticalTextPosition(SwingConstants.TOP);
    jButton2.setHorizontalAlignment(SwingConstants.LEFT);
    jButton2.setText("jButton2");
    jMenuBar1.add(jMenuFile);
    jMenuFile.add(jMenuItem1);
    jMenuFile.add(jMenuFileExit);
    jMenuBar1.add(jMenuHelp);
    jMenuBar1.add(jMenu1);
    jMenuHelp.add(jMenuHelpAbout);
    setJMenuBar(jMenuBar1);
    jMenu1.add(jMenuItem2);
    contentPane.add(jPanel1);
    contentPane.add(jButton1);

  }

  /**
   * File | Exit action performed.
   *
   * @param actionEvent ActionEvent
   */
  void jMenuFileExit_actionPerformed(ActionEvent actionEvent)
  {
    System.exit(0);
  }

  /**
   * Help | About action performed.
   *
   * @param actionEvent ActionEvent
   */
  void jMenuHelpAbout_actionPerformed(ActionEvent actionEvent)
  {
    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.pack();
    dlg.setVisible(true);
  }
}

class Frame1_jMenuFileExit_ActionAdapter
    implements ActionListener
{
  Frame1 adaptee;

  Frame1_jMenuFileExit_ActionAdapter(Frame1 adaptee)
  {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent actionEvent)
  {
    adaptee.jMenuFileExit_actionPerformed(actionEvent);
  }
}

class Frame1_jMenuHelpAbout_ActionAdapter
    implements ActionListener
{
  Frame1 adaptee;

  Frame1_jMenuHelpAbout_ActionAdapter(Frame1 adaptee)
  {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent actionEvent)
  {
    adaptee.jMenuHelpAbout_actionPerformed(actionEvent);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -