我有一个java题目,还没有做好,下午就要交作业了,请各位大姐大哥,帮帮忙,呵呵,是这样的,如下说明:
谢谢了,呵呵 展开
楼上做的已经很好!排版过后的在这里。推荐给你!(我的加上了注释)
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class T3
{
public static void main(String[] args)
{
JFrame jf = new JFrame();//构架fram框架
JPanel inputpanel = new JPanel();//构造panel框架
/**
*设计框架
*/
JLabel jL1 = new JLabel("文本框1");
JLabel jL2 = new JLabel("文本框2");
final JTextField jtf1 = new JTextField();
jtf1.setSize(22,33);
final JTextField jtf2 = new JTextField();
jtf2.setSize(22,33);
inputpanel.setLayout(new GridLayout(2,2));
inputpanel.add(jL1);
inputpanel.add(jtf1);
inputpanel.add(jL2);
inputpanel.add(jtf2);
/**
*设计按钮
*/
JPanel btnpanel = new JPanel();
JButton jb1 = new JButton("清空");
jb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jtf1.setText("");
jtf2.setText("");
}
});
JButton jb2 = new JButton("复制");
jb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jtf2.setText(jtf1.getText());
}
});
JButton jb3 = new JButton("退出");
jb3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
/**
*调用显示布局
*/
btnpanel.add(jb1);
btnpanel.add(jb2);
btnpanel.add(jb3);
jf.setLayout(new GridLayout(2,2));
jf.add(inputpanel);
jf.add(btnpanel);
jf.setVisible(true);
jf.setSize(100,100);
}
}
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class T3 {
public static void main(String[] args) {
JFrame jf = new JFrame();
JPanel inputpanel = new JPanel();
JLabel jL1 = new JLabel("文本框1");
JLabel jL2 = new JLabel("文本框2");
final JTextField jtf1 = new JTextField();
jtf1.setSize(22, 33);
final JTextField jtf2 = new JTextField();
jtf2.setSize(22, 33);
inputpanel.setLayout(new GridLayout(2,2));
inputpanel.add(jL1);
inputpanel.add(jtf1);
inputpanel.add(jL2);
inputpanel.add(jtf2);
JPanel btnpanel = new JPanel();
JButton jb1 = new JButton("清空");
jb1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
jtf1.setText("");
jtf2.setText("");
}});
JButton jb2 = new JButton("复制");
jb2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
jtf2.setText(jtf1.getText());
}
});
JButton jb3 = new JButton("退出");
jb3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
btnpanel.add(jb1);
btnpanel.add(jb2);
btnpanel.add(jb3);
jf.setLayout(new GridLayout(2,1));
jf.add(inputpanel);
jf.add(btnpanel);
jf.setVisible(true);
jf.setSize(222,222);
}
}