java,编写一个GUI界面,使用文本输入组件输入数据
2个回答
展开全部
这是刚才写的
import java.awt.FlowLayout;
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.JTextField;
public class changeTitle extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
public static final int width = 200;
public static final int height = 200;
JTextField text1;
JLabel la;
JButton jbn;
changeTitle(){
setTitle("hello");
setSize(width, height);
setLayout(new FlowLayout());
text1=new JTextField(15);
la=new JLabel("标题:");
jbn=new JButton("更改标题");
add(la);
add(text1);
add(jbn);
jbn.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jbn){
setTitle(text1.getText());
}
}
public static void main(String[] args ){
changeTitle changetitle=new changeTitle();
changetitle.setVisible(true);
changetitle.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.FlowLayout;
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.JTextField;
public class changeTitle extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
public static final int width = 200;
public static final int height = 200;
JTextField text1;
JLabel la;
JButton jbn;
changeTitle(){
setTitle("hello");
setSize(width, height);
setLayout(new FlowLayout());
text1=new JTextField(15);
la=new JLabel("标题:");
jbn=new JButton("更改标题");
add(la);
add(text1);
add(jbn);
jbn.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jbn){
setTitle(text1.getText());
}
}
public static void main(String[] args ){
changeTitle changetitle=new changeTitle();
changetitle.setVisible(true);
changetitle.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把问题说详细一点
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询