当前位置: 技术问答>java相关
help,help!!!
来源: 互联网 发布时间:2015-04-21
本文导语: why can't dispay popmenu in this program? primary code: import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.beans.*; public class Frame1 extends JFrame implements MouseMotionListener { JPanel contentPane; BorderLayout borderLay...
why can't dispay popmenu in this program?
primary code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;
public class Frame1 extends JFrame implements MouseMotionListener {
JPanel contentPane;
BorderLayout borderLayout1;
JScrollPane jScrollPane1;
JTextArea jTextArea1;
JPopupMenu jPopupMenu1;
JMenuItem jMenuItem1;
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
borderLayout1 = (BorderLayout)Beans.instantiate(getClass().getClassLoader(),BorderLayout.class.getName());
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jScrollPane1 = (JScrollPane) Beans.instantiate(getClass().getClassLoader(), JScrollPane.class.getName());
jTextArea1 = (JTextArea) Beans.instantiate(getClass().getClassLoader(), JTextArea.class.getName());
jPopupMenu1 = (JPopupMenu) Beans.instantiate(getClass().getClassLoader(), JPopupMenu.class.getName());
jMenuItem1 = (JMenuItem) Beans.instantiate(getClass().getClassLoader(), JMenuItem.class.getName());
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jMenuItem1.setText("Open");
contentPane.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextArea1, null);
jPopupMenu1.add(jMenuItem1);
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent evt)
{
jPopupMenu1.show(this,evt.getX(),evt.getY());
}
});
}
//Overridden so we can exit when window is closed
public void mouseMoved(MouseEvent evt)
{
}
public void mouseDragged(MouseEvent evt)
{
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
primary code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;
public class Frame1 extends JFrame implements MouseMotionListener {
JPanel contentPane;
BorderLayout borderLayout1;
JScrollPane jScrollPane1;
JTextArea jTextArea1;
JPopupMenu jPopupMenu1;
JMenuItem jMenuItem1;
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
borderLayout1 = (BorderLayout)Beans.instantiate(getClass().getClassLoader(),BorderLayout.class.getName());
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jScrollPane1 = (JScrollPane) Beans.instantiate(getClass().getClassLoader(), JScrollPane.class.getName());
jTextArea1 = (JTextArea) Beans.instantiate(getClass().getClassLoader(), JTextArea.class.getName());
jPopupMenu1 = (JPopupMenu) Beans.instantiate(getClass().getClassLoader(), JPopupMenu.class.getName());
jMenuItem1 = (JMenuItem) Beans.instantiate(getClass().getClassLoader(), JMenuItem.class.getName());
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jMenuItem1.setText("Open");
contentPane.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextArea1, null);
jPopupMenu1.add(jMenuItem1);
addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent evt)
{
jPopupMenu1.show(this,evt.getX(),evt.getY());
}
});
}
//Overridden so we can exit when window is closed
public void mouseMoved(MouseEvent evt)
{
}
public void mouseDragged(MouseEvent evt)
{
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
|
有几个错误,都给你改正过来了。以下代码我已经调试通过:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;
public class Frame1 extends JFrame implements MouseMotionListener {
JPanel contentPane;
BorderLayout borderLayout1;
JScrollPane jScrollPane1;
JTextArea jTextArea1;
JPopupMenu jPopupMenu1;
JMenuItem jMenuItem1;
public static void main(String[] args)
{
Frame1 frame=new Frame1();
frame.setBounds(100,100,300,300);
frame.show();
}
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
borderLayout1 = (BorderLayout)Beans.instantiate(getClass().getClassLoader(),BorderLayout.class.getName());
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jScrollPane1 = (JScrollPane) Beans.instantiate(getClass().getClassLoader(), JScrollPane.class.getName());
jTextArea1 = (JTextArea) Beans.instantiate(getClass().getClassLoader(), JTextArea.class.getName());
jPopupMenu1 = (JPopupMenu) Beans.instantiate(getClass().getClassLoader(), JPopupMenu.class.getName());
jMenuItem1 = (JMenuItem) Beans.instantiate(getClass().getClassLoader(), JMenuItem.class.getName());
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jMenuItem1.setText("Open");
contentPane.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextArea1, null);
jPopupMenu1.add(jMenuItem1);
jTextArea1.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent evt)
{
jPopupMenu1.show(jTextArea1,evt.getX(),evt.getY());
}
});
}
//Overridden so we can exit when window is closed
public void mouseMoved(MouseEvent evt)
{
}
public void mouseDragged(MouseEvent evt)
{
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;
public class Frame1 extends JFrame implements MouseMotionListener {
JPanel contentPane;
BorderLayout borderLayout1;
JScrollPane jScrollPane1;
JTextArea jTextArea1;
JPopupMenu jPopupMenu1;
JMenuItem jMenuItem1;
public static void main(String[] args)
{
Frame1 frame=new Frame1();
frame.setBounds(100,100,300,300);
frame.show();
}
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
borderLayout1 = (BorderLayout)Beans.instantiate(getClass().getClassLoader(),BorderLayout.class.getName());
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
jScrollPane1 = (JScrollPane) Beans.instantiate(getClass().getClassLoader(), JScrollPane.class.getName());
jTextArea1 = (JTextArea) Beans.instantiate(getClass().getClassLoader(), JTextArea.class.getName());
jPopupMenu1 = (JPopupMenu) Beans.instantiate(getClass().getClassLoader(), JPopupMenu.class.getName());
jMenuItem1 = (JMenuItem) Beans.instantiate(getClass().getClassLoader(), JMenuItem.class.getName());
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jMenuItem1.setText("Open");
contentPane.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextArea1, null);
jPopupMenu1.add(jMenuItem1);
jTextArea1.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent evt)
{
jPopupMenu1.show(jTextArea1,evt.getX(),evt.getY());
}
});
}
//Overridden so we can exit when window is closed
public void mouseMoved(MouseEvent evt)
{
}
public void mouseDragged(MouseEvent evt)
{
}
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。