帮我看一下,这个Java程序中的复制与粘贴功能怎样才能实现
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclasslianxi1extends...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class lianxi1 extends JFrame implements ActionListener{
JPanel n,n5,n6;
JButton n1,n2,n7,n8;
TextField n3;
TextArea n4;
public lianxi1(){
super("我的练习");
this.setSize(600, 600);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
n=new JPanel();
this.add(n);
n5=new JPanel();
n3=new TextField(20);
n1=new JButton("发送");
n2=new JButton("删除");
n7=new JButton("复制");
n8=new JButton("粘贴");
n1.addActionListener(this);
n2.addActionListener(this);
n7.addActionListener(this);
n8.addActionListener(this);
n5.add(n3); n5.add(n1); n5.add(n2); n5.add(n7); n5.add(n8);
n.add(n5);
n6=new JPanel();
n4=new TextArea();
n6.add(n4);
n.add(n6);
n2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
n4.setText("");
n4.repaint();
}
});
n2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
n3.setText("");
n3.repaint();
}
});}
public static void main(String[] args) {
new lianxi1();
}
public void actionPerformed(ActionEvent e) {
if( e.getSource()==n1 ){
if(!"".equals(n3.getText())){
n4.setText(n3.getText());}
}
}
} 展开
import java.awt.event.*;
import javax.swing.*;
public class lianxi1 extends JFrame implements ActionListener{
JPanel n,n5,n6;
JButton n1,n2,n7,n8;
TextField n3;
TextArea n4;
public lianxi1(){
super("我的练习");
this.setSize(600, 600);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
n=new JPanel();
this.add(n);
n5=new JPanel();
n3=new TextField(20);
n1=new JButton("发送");
n2=new JButton("删除");
n7=new JButton("复制");
n8=new JButton("粘贴");
n1.addActionListener(this);
n2.addActionListener(this);
n7.addActionListener(this);
n8.addActionListener(this);
n5.add(n3); n5.add(n1); n5.add(n2); n5.add(n7); n5.add(n8);
n.add(n5);
n6=new JPanel();
n4=new TextArea();
n6.add(n4);
n.add(n6);
n2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
n4.setText("");
n4.repaint();
}
});
n2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
n3.setText("");
n3.repaint();
}
});}
public static void main(String[] args) {
new lianxi1();
}
public void actionPerformed(ActionEvent e) {
if( e.getSource()==n1 ){
if(!"".equals(n3.getText())){
n4.setText(n3.getText());}
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询