javagui清空_关于JavaGUI并清除JFrame以显⽰新内容?我正在学习Java和GUI。我有⼀些问题,⾸先是创建JFrame的⼦类和JFrame的实例之间有什么主要区别。看起来像⼀个⼦类更强⼤?我也想知道是否有必要使⽤创建GUI时这个代码:关于Java GUI并清除JFrame以显⽰新内容?
Container contentPane = getContentPane();
contentPane.setLayot(new Flowlayout());
添加我的GUI类,这是⼀个简单的测试,到⽬前为⽌,到我⼿的任务。当⽤户输⼊。⽂本框中的⼀些⽂本,然后按按钮继续下⼀步,我该如何清除框架并显⽰新内容,或者有没有⼀种特殊的⽅法可以在Java中执⾏此操作?我想最好是使⽤相同的窗⼝⽽不是创建新的!?帮助ID preciated!由于html内容文本框
// Gui class
import java.awt.FlowLayout; // layout
import java.awt.event.ActionListener; // listener
import java.awt.event.ActionEvent; // event
import javax.swing.JFrame; // windows properties
import javax.swing.JLabel; // row of text
import javax.swing.JTextField; // enter text
import javax.swing.JOptionPane; // pop up dialog
import javax.swing.JButton; // buttons
// import.javax.swing.*;
public class Gui extends JFrame {
private JLabel text1;
private JTextField textInput1;
private JTextField textInput2;
private JButton nextButton;
// constructor creates the window and it's components
public Gui() {
super("Bank"); // title
setLayout(new FlowLayout()); // set default layout
text1 = new JLabel("New customer");
add(text1);
textInput1 = new JTextField(10);
add(textInput1);
nextButton = new JButton("Continue");
add(nextButton);
// create object to handle the components (action listener object)
frameHandler handler = new frameHandler();
textInput1.addActionListener(handler);
nextButton.addActionListener(handler);
}
// handle the events (class inside another class inherits contents from class outside) private class frameHandler implements ActionListener {
public void actionPerformed(ActionEvent event){
String input1 = "";
// check if someone hits enter at first textfield
Source() == textInput1){
input1 = String.ActionCommand());
JOptionPane.showMessageDialog(null, input1);
}
else Source() == nextButton){
// ??
}
}
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论