MFC怎样让点击按钮后,窗口形状改变。 20
2个回答
2018-05-23 · 知道合伙人互联网行家
关注
展开全部
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Frame1 extends JFrame {
public static JTextField tf;
public Frame1() {
tf = new JTextField();
add(tf);
setSize(200, 100);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Frame2 extends JFrame {
private JButton button;
public Frame2(){
button = new JButton("触发");
add(button);
setSize(50, 50);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Frame1.tf.setText("事件触发,改变JTextField的值");
}
});
}
}
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Frame1 f1 = new Frame1();
Frame2 f2 = new Frame2();
f1.setVisible(true);
f2.setVisible(true);
}
}
import javax.swing.JTextField;
public class Frame1 extends JFrame {
public static JTextField tf;
public Frame1() {
tf = new JTextField();
add(tf);
setSize(200, 100);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Frame2 extends JFrame {
private JButton button;
public Frame2(){
button = new JButton("触发");
add(button);
setSize(50, 50);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Frame1.tf.setText("事件触发,改变JTextField的值");
}
});
}
}
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Frame1 f1 = new Frame1();
Frame2 f2 = new Frame2();
f1.setVisible(true);
f2.setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询