以下关于java的GUI菜单描述_Java GUI 的菜单问题

//这段程序清除选项可以实现清除但是如何让菜单栏里面文件下的子菜单“清除”也实现清除呢?谁能帮忙改//下代码谢谢第二个问题。想在(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();

}

}

//接下去的代码

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值