The problem and question is in line 50-51:
package exercise1;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class MainFrame extends JFrame {
// -------------------------------------------------------------------------
public static void main(String[] args) {
MainFrame frame = new MainFrame();
frame.pack();
frame.setVisible(true);
}
public MainFrame() {
this.setTitle("Exercise 1");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(300, 200);
this.getContentPane().setPreferredSize(new Dimension(400, 150));
this.getContentPane().setLayout(null);
this.initContent();
}
// -------------------------------------------------------------------------
private final JButton btnCombine = new JButton();
private void initContent() {
this.add(btnTest);
btnTest.setText("Change Size");
btnTest.setSize(100, 25);
btnTest.setLocation(150, 100);
btnTest.addActionListener(action);
}
// -------------------------------------------------------------------------
private final Controller action = new Controller();
private class Controller implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnTest) {
//CHANGE THE WINDOWS SIZE HERE;
MainFrame.getContentPane().setPreferredSize(new Dimension(100, 200));
}
}
}
}
How I can change the size of windows, if I have code like this?
There is one condition: I want to change the size of it on the button click. In this example: I click on button btnTest and the size of windows changes to no matter what else size.
Thanks! :)