前两天考计算机二级的时候遇到的一个题目,卡了我半个多小时,一直想不出来要继承什么类,求助大神,帮我过了这个梗吧
![](http://imgsrc.baidu.com/forum/w%3D580/sign=b2f8514611950a7b75354ecc3ad0625c/556e49166d224f4ade54796305f790529922d103.jpg)
题目代码
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
//*********Found**********
public class Java_3 extends ______________________ implements ActionListener
{
//*********Found**********
private ____________________ pop;
private JMenu subPop;
private JMenuItem color;
private JMenuItem exit;
private JMenuItem red;
private JMenuItem blue;
private JTextArea textArea;
private JFrame frame;
public void initGUI()
{
pop=new JPopupMenu();
subPop=new JMenu("color");
//*********Found**********
red=new JMenuItem("______________________");
red.addActionListener(this);
blue=new JMenuItem("blue");
blue.addActionListener(this);
subPop.add(red);
subPop.add(blue);
exit=new JMenuItem("exit");
exit.addActionListener(this);
pop.add(subPop);
pop.add(exit);
frame=new JFrame("popup frame");
textArea=new JTextArea("",10,10);
textArea.addMouseListener(this);
//*********Found**********
frame.getContentPane().add(____________________);
frame.setSize(300,300);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource()==red)
{
//*********Found**********
textArea.setForeground(Color._____________________);
textArea.setText("red menu is selected");
}
else if(event.getSource()==blue)
{
textArea.setForeground(Color.blue);
textArea.setText("blue menu is selected");
}
else if(event.getSource()==exit)
{
frame.setVisible(false);
System.exit(0);
}
}
public void mousePressed(MouseEvent e)
{
if(e.getModifiers()==e.BUTTON3_MASK)
{
pop.show(e.getComponent(),e.getX(),e.getY());
}
}
public static void main(String args[])
{
Java_3 example=new Java_3();
example.initGUI();
}
}
![](http://imgsrc.baidu.com/forum/w%3D580/sign=b2f8514611950a7b75354ecc3ad0625c/556e49166d224f4ade54796305f790529922d103.jpg)
题目代码
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
//*********Found**********
public class Java_3 extends ______________________ implements ActionListener
{
//*********Found**********
private ____________________ pop;
private JMenu subPop;
private JMenuItem color;
private JMenuItem exit;
private JMenuItem red;
private JMenuItem blue;
private JTextArea textArea;
private JFrame frame;
public void initGUI()
{
pop=new JPopupMenu();
subPop=new JMenu("color");
//*********Found**********
red=new JMenuItem("______________________");
red.addActionListener(this);
blue=new JMenuItem("blue");
blue.addActionListener(this);
subPop.add(red);
subPop.add(blue);
exit=new JMenuItem("exit");
exit.addActionListener(this);
pop.add(subPop);
pop.add(exit);
frame=new JFrame("popup frame");
textArea=new JTextArea("",10,10);
textArea.addMouseListener(this);
//*********Found**********
frame.getContentPane().add(____________________);
frame.setSize(300,300);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent event)
{
if(event.getSource()==red)
{
//*********Found**********
textArea.setForeground(Color._____________________);
textArea.setText("red menu is selected");
}
else if(event.getSource()==blue)
{
textArea.setForeground(Color.blue);
textArea.setText("blue menu is selected");
}
else if(event.getSource()==exit)
{
frame.setVisible(false);
System.exit(0);
}
}
public void mousePressed(MouseEvent e)
{
if(e.getModifiers()==e.BUTTON3_MASK)
{
pop.show(e.getComponent(),e.getX(),e.getY());
}
}
public static void main(String args[])
{
Java_3 example=new Java_3();
example.initGUI();
}
}
![](http://e.hiphotos.baidu.com/album/s%3D1000%3Bq%3D90/sign=d3d80a59ac345982c18ae1923cc40adc/d01373f082025aafe00ae0e6faedab64034f1ae6.jpg?v=tbs)