java编写图形界面应用程序,其中包括一个文本框和一个按钮.用户单击按钮后,窗口的标题为文本框中的内容
展开全部
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.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);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询