急求java程序设计达人解答!!!!
编写一个程序,使之具有如下图所示的界面,并实现简单的控制:按Clear按钮清空两个文本框的内容;按Copy按钮将Source文本框的内容复制到Target文本框;按Clo...
编写一个程序,使之具有如下图所示的界面,并实现简单的控制:按Clear按钮清空两个文本框的内容;按Copy按钮将Source文本框的内容复制到Target文本框;按Close按钮则结束程序的运行
只要代码就可以了,谢谢了
图片我弄丢了,
Soucre :文本框
Target:文本框
Clear copy
大体上是这样的 展开
只要代码就可以了,谢谢了
图片我弄丢了,
Soucre :文本框
Target:文本框
Clear copy
大体上是这样的 展开
2个回答
展开全部
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
ba = new javax.swing.JButton();
bb = new javax.swing.JButton();
bc = new javax.swing.JButton();
la = new javax.swing.JTextField();
lb = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
ba.setText("Clear");
ba.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
baActionPerformed(evt);
}
});
bb.setText("Copy");
bb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bbActionPerformed(evt);
}
});
bc.setText("Close");
bc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bcActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(52, 52, 52)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lb, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(la, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(ba)
.addGap(26, 26, 26)
.addComponent(bb)
.addGap(32, 32, 32)
.addComponent(bc)))
.addContainerGap(52, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(la, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lb, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ba)
.addComponent(bb)
.addComponent(bc))
.addContainerGap(29, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void baActionPerformed(java.awt.event.ActionEvent evt) {
la.setText(null);
lb.setText(null);
}
private void bbActionPerformed(java.awt.event.ActionEvent evt) {
lb.setText(la.getText());
}
private void bcActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton ba;
private javax.swing.JButton bb;
private javax.swing.JButton bc;
private javax.swing.JTextField la;
private javax.swing.JTextField lb;
// End of variables declaration
}
public NewJFrame() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
ba = new javax.swing.JButton();
bb = new javax.swing.JButton();
bc = new javax.swing.JButton();
la = new javax.swing.JTextField();
lb = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
ba.setText("Clear");
ba.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
baActionPerformed(evt);
}
});
bb.setText("Copy");
bb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bbActionPerformed(evt);
}
});
bc.setText("Close");
bc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bcActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(52, 52, 52)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lb, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(la, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(ba)
.addGap(26, 26, 26)
.addComponent(bb)
.addGap(32, 32, 32)
.addComponent(bc)))
.addContainerGap(52, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(la, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(lb, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ba)
.addComponent(bb)
.addComponent(bc))
.addContainerGap(29, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void baActionPerformed(java.awt.event.ActionEvent evt) {
la.setText(null);
lb.setText(null);
}
private void bbActionPerformed(java.awt.event.ActionEvent evt) {
lb.setText(la.getText());
}
private void bcActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton ba;
private javax.swing.JButton bb;
private javax.swing.JButton bc;
private javax.swing.JTextField la;
private javax.swing.JTextField lb;
// End of variables declaration
}
展开全部
import java.awt.Dimension;
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 Test extends JFrame {
private JPanel p;
private JLabel labSource;
private JLabel labTarget;
private JTextField txtSource;
private JTextField txtTarget;
private JButton btnClear;
private JButton btnCopy;
public Test() {
p=new JPanel();
labSource=new JLabel("Source:");
labTarget=new JLabel("Target:");
txtSource=new JTextField(12);
txtTarget=new JTextField(12);
btnClear=new JButton("Clear");
btnCopy=new JButton("Copy");
p.add(labSource);
p.add(txtSource);
p.add(labTarget);
p.add(txtTarget);
p.add(btnClear);
btnClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
txtSource.setText("");
txtTarget.setText("");
}
});
p.add(btnCopy);
btnCopy.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
txtTarget.setText(txtSource.getText());
}
});
this.setTitle("复制程序");
this.setBounds(600, 300, 200,100);
this.add(p);
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
this.setResizable(false);
this.setSize(new Dimension(200,200));
}
public static void main(String[] args) {
new Test().setVisible(true);
}
}
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 Test extends JFrame {
private JPanel p;
private JLabel labSource;
private JLabel labTarget;
private JTextField txtSource;
private JTextField txtTarget;
private JButton btnClear;
private JButton btnCopy;
public Test() {
p=new JPanel();
labSource=new JLabel("Source:");
labTarget=new JLabel("Target:");
txtSource=new JTextField(12);
txtTarget=new JTextField(12);
btnClear=new JButton("Clear");
btnCopy=new JButton("Copy");
p.add(labSource);
p.add(txtSource);
p.add(labTarget);
p.add(txtTarget);
p.add(btnClear);
btnClear.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
txtSource.setText("");
txtTarget.setText("");
}
});
p.add(btnCopy);
btnCopy.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
txtTarget.setText(txtSource.getText());
}
});
this.setTitle("复制程序");
this.setBounds(600, 300, 200,100);
this.add(p);
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
this.setResizable(false);
this.setSize(new Dimension(200,200));
}
public static void main(String[] args) {
new Test().setVisible(true);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询