java gui 选项_Java GUI 的菜单栏不能显示

importjava.awt.*;importjava.awt.event.*;importjava.io.*;importjavax.swing.*;publicclassprintspecextendsJFrameimplementsActionListener{staticfinalStringOUTPUT="C://Test.tx...

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("文件");//文件菜单

public printspec()

{

super("printspec");

pnl=new JPanel();//中间容器

this.setContentPane(pnl);///意思是给窗体加个pane

pnl.setLayout(null);//设置jpane;的布局管理器为空啊,你就可以自己手动的设置组件的坐标位置和大小了

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("变色");

//menubar1= new JMenuBar();

//menu1 =new JMenu("1");

btnColor.addActionListener(this);

//menu1.setBounds(10, 10, 80, 20);

lbl.setBounds(100, 10, 80, 20);

txt1.setBounds(10, 40, 100, 20);

txt2.setBounds(120, 40, 100, 20);

btnCopy.setBounds(10, 70, 60, 20);

btnClear.setBounds(75, 70, 60, 20);

btnOutput.setBounds(140, 70, 60, 20);

btnColor.setBounds(205, 70, 60, 20);

pnl.add(lbl);

pnl.add(txt1);

pnl.add(txt2);

pnl.add(btnCopy);

pnl.add(btnClear);

pnl.add(btnOutput);

pnl.add(btnColor);

setSize(1100,700);

setVisible(true);

//init();

}

public void Copy()

{

txt2.setText(txt1.getText());

}

public void Clear()

{

txt1.setText("");

txt2.setText("");

pnl.setBackground(Color.WHITE);

}

public void Color()

{

pnl.setBackground(Color.BLACK);

}

public void Ouput()

{

try

{

File fl=new File("C:\\Test.txt");

FileWriter fw = new FileWriter(fl);

BufferedWriter bw = new BufferedWriter(fw);

bw.write(txt1.getText());

bw.close();

}

catch (IOException e)

{

e.printStackTrace();

}

}

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();

}

}

//这是我的代码 但是不能显示出最简单的菜单栏 求修改 让我能显示出菜单栏 是“文件”与“属性”两个菜单

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值