JAVA图形界面程序编写

2022-04-20 科技 65阅读
我真的是抽风了,手痒了,给你写了这段代码,如果楼主、、、
嘻嘻,追点分给我吧

importjava.awt.*;
importjava.awt.event.*;
importjava.io.*;
importjavax.swing.*;

publicclassbaidu_9extendsJFrameimplementsActionListener
{
staticfinalStringOUTPUT="C://Test.txt";
JPanelpnl;
JLabellbl;
JTextFieldtxt1,txt2;
JButtonbtnCopy,btnClear,btnOutput,btnColor;
publicbaidu_9()
{
super("百度题目");
pnl=newJPanel();
this.setContentPane(pnl);
pnl.setLayout(null);
pnl.setBackground(Color.WHITE);
lbl=newJLabel("百度");
txt1=newJTextField(10);
txt2=newJTextField(10);
btnCopy=newJButton("复制");
btnCopy.addActionListener(this);
btnClear=newJButton("清除");
btnClear.addActionListener(this);
btnOutput=newJButton("写入");
btnOutput.addActionListener(this);
btnColor=newJButton("变色");
btnColor.addActionListener(this);
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(300,150);
setVisible(true);
}
publicvoidCopy()
{
txt2.setText(txt1.getText());
}
publicvoidClear()
{
txt1.setText("");
txt2.setText("");
pnl.setBackground(Color.WHITE);
}
publicvoidColor()
{
pnl.setBackground(Color.BLACK);
}
publicvoidOuput()
{
try
{
Filefl=newFile("C:\\Test.txt");
FileWriterfw=newFileWriter(fl);
BufferedWriterbw=newBufferedWriter(fw);
bw.write(txt1.getText());
bw.close();
}
catch(IOExceptione)
{
e.printStackTrace();
}
}
publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==btnCopy)
this.Copy();
if(e.getSource()==btnClear)
this.Clear();
if(e.getSource()==btnColor)
this.Color();
if(e.getSource()==btnOutput)
this.Ouput();
}
publicstaticvoidmain(String[]args)
{
newbaidu_9();
}
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com