//这段程序清除选项可以实现清除但是如何让菜单栏里面文件下的子菜单“清除”也实现清除呢?谁能帮忙改//下代码谢谢第二个问题。想在(100,100)这个位置放一个红色色块importjava.a...
//这段程序清除选项可以实现清除 但是如何让菜单栏里面文件下的子菜单“清除”也实现清除呢?谁能帮忙改
//下代码 谢谢 第二个问题 。想在(100,100)这个位置放一个红色色块
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class printspec extends JFrame implements ActionListener
{
static final String OUTPUT="C://Test.txt";
JPanel pnl;
JLabel lbl;
JTextField txt1,txt2;
JButton btnCopy,btnClear,btnOutput,btnColor;
JMenuBar mb=new JMenuBar();//菜单栏
JMenu file=new JMenu("文件");//文件菜单
JMenu file2=new JMenu("属性");//文件菜单
// JMenuItem fileNew=new JMenuItem("新建");
public printspec()
{
super("printspec");
pnl=new JPanel();//中间容器
this.setContentPane(pnl);
pnl.setLayout(null);
pnl.setBackground(Color.WHITE);
lbl=new JLabel("百度");
//lbl.setBounds(300,100,20,25);
txt1=new JTextField("ok,",10);//提示输入的文字 以及字符长度 最多为10
txt2=new JTextField(10);
btnCopy=new JButton("复制");
btnCopy.addActionListener(this);
btnClear=new JButton("清除");
btnClear.addActionListener(this);
btnOutput=new JButton("写入");
btnOutput.addActionListener(this);
btnColor=new JButton("变色");
file.add(new JMenuItem("复制"));
file.add(new JMenuItem("清除"));
file.add(new JMenuItem("写入"));
file.add(new JMenuItem("变色"));
mb.add(file);
mb.add(file2);
setJMenuBar(mb);
// setJMenuBar(mb2);
//menubar1= new JMenuBar();
//fileNew.addActionListener(new ActionListener());
//fileNew.addActionListener(new Act_NewFile());
//file.add(fileNew);
//mb.add(file);
//menu1 =new JMenu("1");
btnColor.addActionListener(this);
//menu1.setBounds(10, 10, 80, 20);
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnCopy)
this.Copy();
if(e.getSource()==btnClear)
this.Clear();
if(e.getSource()==btnColor)
this.Color();
if(e.getSource()==btnOutput)
this.Ouput();
}
public static void main(String[] args)
{
new printspec();
}
}
//接下去的代码
展开