当前位置: 技术问答>java相关
jb 中popup menu 如何使用??
来源: 互联网 发布时间:2015-04-29
本文导语: 初学java 请问 jb5 中popup menu 如何使用?? 能详细点吗?? | package untitled5; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Frame1 extends JFrame { JPanel contentPane; JButton jButton1 = ...
初学java 请问 jb5 中popup menu 如何使用??
能详细点吗??
能详细点吗??
|
package untitled5;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame
{
JPanel contentPane;
JButton jButton1 = new JButton();
JPopupMenu jPopupMenu1 = new JPopupMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem2 = new JMenuItem();
//Construct the frame
public Frame1()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jButton1.setBounds(new Rectangle(119, 98, 79, 29));
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jButton1_actionPerformed(e);
}
});
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jMenuItem1.setText("fdg");
jMenuItem2.setText("gggg");
jPopupMenu1.addSeparator();
jPopupMenu1.add(jMenuItem1);
jPopupMenu1.add(jMenuItem2);
contentPane.add(jButton1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
void jButton1_actionPerformed(ActionEvent e)
{
jPopupMenu1.show(this,90,90);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame
{
JPanel contentPane;
JButton jButton1 = new JButton();
JPopupMenu jPopupMenu1 = new JPopupMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem2 = new JMenuItem();
//Construct the frame
public Frame1()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception
{
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jButton1.setBounds(new Rectangle(119, 98, 79, 29));
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jButton1_actionPerformed(e);
}
});
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jMenuItem1.setText("fdg");
jMenuItem2.setText("gggg");
jPopupMenu1.addSeparator();
jPopupMenu1.add(jMenuItem1);
jPopupMenu1.add(jMenuItem2);
contentPane.add(jButton1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
void jButton1_actionPerformed(ActionEvent e)
{
jPopupMenu1.show(this,90,90);
}
}