import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test1 extends javax.swing.JFrame {
{
//Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch(Exception e) {
e.printStackTrace();
}
}
private JMenuBar jMenuBar1;
private JPanel jPanel1;
private JButton jButton1;
private JMenuItem jMenuItem2;
private JMenuItem jMenuItem1;
private JMenu jMenu2;
private JMenu jMenu1;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
Test1 inst = new Test1();
inst.setVisible(true);
}
public Test1() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
{
jPanel1 = new JPanel();
FlowLayout jPanel1Layout = new FlowLayout();
jPanel1Layout.setAlignment(FlowLayout.LEFT);
getContentPane().add(jPanel1, BorderLayout.NORTH);
jPanel1.setLayout(jPanel1Layout);
{
jButton1 = new JButton();
jPanel1.add(jButton1);
jButton1.setText("关于(A)");
jButton1.setMnemonic('A');//快捷键ALT+A
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
}
}
{
jMenuBar1 = new JMenuBar();
setJMenuBar(jMenuBar1);
{
jMenu1 = new JMenu();
jMenuBar1.add(jMenu1);
jMenu1.setText("文件(F)");
jMenu1.setMnemonic('F');
{
jMenuItem1 = new JMenuItem();
jMenu1.add(jMenuItem1);
jMenuItem1.setText("关闭(E)");
jMenuItem1.setMnemonic('E');
jMenuItem1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
}
}
{
jMenu2 = new JMenu();
jMenuBar1.add(jMenu2);
jMenu2.setText("帮助(H)");
jMenu2.setMnemonic('H');
{
jMenuItem2 = new JMenuItem();
jMenu2.add(jMenuItem2);
jMenuItem2.setText("关于(A)");
jMenuItem2.setMnemonic('A');
jMenuItem2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
}
}
}
pack();
setSize(400, 300);
setLocationRelativeTo(null);
} catch (Exception e) {
e.printStackTrace();
}
}
//菜单 "关闭"
private void jMenuItem1ActionPerformed(ActionEvent evt) {
System.exit(0);
}
//按钮 "关于"
private void jButton1ActionPerformed(ActionEvent evt) {
final JDialog jDialog1=new JDialog();
jDialog1.setTitle("关于");
jDialog1.setSize(240, 180);
JTextArea jTextArea1=new JTextArea();
jTextArea1.setText("我爱java");
jTextArea1.append("\n书名:XXXXXX");
jTextArea1.append("\n作者:XXXXXX");
jTextArea1.append("\n出版社:XXXXXX");
jTextArea1.append("\n出版日期:XXXXXX");
jTextArea1.setEditable(false);
jDialog1.getContentPane().add(jTextArea1,BorderLayout.CENTER);
JButton jButton2=new JButton("关闭(X)");
jButton2.setMnemonic('X');
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jDialog1.dispose();
}
});
JPanel jPane2=new JPanel();
FlowLayout jPanel2Layout = new FlowLayout();
jPanel2Layout.setAlignment(FlowLayout.CENTER);
jPane2.setLayout(jPanel2Layout);
jPane2.add(jButton2);
jDialog1.add(jPane2,BorderLayout.SOUTH);
jDialog1.setLocationRelativeTo(this);
jDialog1.setModal(true);
jDialog1.setVisible(true);
}
//菜单 "关于"
private void jMenuItem2ActionPerformed(ActionEvent evt) {
jButton1.doClick();
}
}
给人民币给你做!给点分就想让人做,除非有现成代码,其实我也有现成代码,改改就OK了!不过想想现在混的不好,老给你们高薪人解决问题,而我们却失业中,社会很不公平哦!也难怪最近中国老发生暴乱(天天发生一人砍死N人的事件),都是给人逼的