1个回答
展开全部
package com.test;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class test3 extends JFrame implements ActionListener{
/**
* @param args
*/
//定义组件
JLabel jl;
JPanel jp;
JButton jb;
JTextField jtf;
public static void main(String[] args) {
// TODO Auto-generated method stub
test3 t=new test3();
}
public test3(){
jl=new JLabel();
jtf=new JTextField("",13);
jb=new JButton("点我");
jb.addActionListener(this);
jp=new JPanel();
jp.add(jtf);jp.add(jb);jp.add(jl);
this.add(jp);
this.setVisible(true);
this.setBounds(420, 150, 300,300);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jb){
this.jl.setText(jtf.getText());
}
}
}
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class test3 extends JFrame implements ActionListener{
/**
* @param args
*/
//定义组件
JLabel jl;
JPanel jp;
JButton jb;
JTextField jtf;
public static void main(String[] args) {
// TODO Auto-generated method stub
test3 t=new test3();
}
public test3(){
jl=new JLabel();
jtf=new JTextField("",13);
jb=new JButton("点我");
jb.addActionListener(this);
jp=new JPanel();
jp.add(jtf);jp.add(jb);jp.add(jl);
this.add(jp);
this.setVisible(true);
this.setBounds(420, 150, 300,300);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jb){
this.jl.setText(jtf.getText());
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询