java点击菜单项弹出窗口怎么弄
我在做一个小程序,要实现点击一个菜单项,弹出一个窗口,代码如下:packagecalc;importjava.awt.Dimension;importjava.awt.e...
我在做一个小程序,要实现点击一个菜单项,弹出一个窗口,代码如下:
package calc;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
public class TextCode {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame textJFrame = new JFrame("测试菜单事件");
JMenuBar menuBar = new JMenuBar();
JMenu abouJMenu = new JMenu("关于");
JMenuItem authors = new JMenuItem("作者");
menuBar.add(abouJMenu);
abouJMenu.add(authors);
authors.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JFrame authorFrame = new JFrame("作者");
JTextArea authorTextArea = new JTextArea("作者: BlueKing");
authorTextArea.setPreferredSize(new Dimension(40, 80));
authorFrame.add(authorTextArea);
}
});
textJFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
System.exit(1);
}
});
textJFrame.setJMenuBar(menuBar);
textJFrame.setBounds(300, 100, 220, 280);
textJFrame.setResizable(false);
textJFrame.setVisible(true);
}
} 展开
package calc;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
public class TextCode {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame textJFrame = new JFrame("测试菜单事件");
JMenuBar menuBar = new JMenuBar();
JMenu abouJMenu = new JMenu("关于");
JMenuItem authors = new JMenuItem("作者");
menuBar.add(abouJMenu);
abouJMenu.add(authors);
authors.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JFrame authorFrame = new JFrame("作者");
JTextArea authorTextArea = new JTextArea("作者: BlueKing");
authorTextArea.setPreferredSize(new Dimension(40, 80));
authorFrame.add(authorTextArea);
}
});
textJFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
System.exit(1);
}
});
textJFrame.setJMenuBar(menuBar);
textJFrame.setBounds(300, 100, 220, 280);
textJFrame.setResizable(false);
textJFrame.setVisible(true);
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询