I'm trying to create a simple GUI where a list of data objects will be displayed. Then there will be various buttons to modify a selected object from this list or change to a different screen.
So far I planned to have a global Jframe window while components are added and removed on screen changes.
So far I cant even display have one button where if clicked, the JFrame clears all components from the window. When the button is clicked, it just freezes. Also its very buggy as I run it in Eclipse. Sometimes the button is sized properly. Other times the button is the size of the entire JFrame.
So far I planned to have a global Jframe window while components are added and removed on screen changes.
So far I cant even display have one button where if clicked, the JFrame clears all components from the window. When the button is clicked, it just freezes. Also its very buggy as I run it in Eclipse. Sometimes the button is sized properly. Other times the button is the size of the entire JFrame.
Code:
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.net.URL;
import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
//import UI.AppWindow;
//import statements
//Check if window closes automatically. Otherwise add suitable code
public class gu extends JFrame {
JFrame window = new JFrame("Test");
JButton b;
public static void main(String args[]) {
gu testrun = new gu();
testrun.more();
}
public void more()
{
window.setSize(800, 600);
window.show();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b = new JButton("CLICK THIS");
b.setSize(100,70);
b.setOpaque(true);
window.setContentPane(b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
clearframe();
}
});
}
public void clearframe()
{
window.removeAll();
window.validate();
window.repaint();
}
}