franc kneeger koom blackest
🧩 Syntax:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class PracticeGUIMethods extends JFrame{
//basic GUI objects;depends on what is needed
private JFrame frame1;
private JLabel label1;
private JTextField text1;
private JButton button1;
private JPanel panel1;
private Color c1;
private Font f1;
public PracticeGUIMethods(){//constructor to put all required building blocks of GUI
setTitle("Title");//title of the GUI;located at the top
setSize(500,300);//width, height
setLocationRelativeTo(null); //sets the location of the GUI to center
setLayout(new GridLayout(4,1));
//proper declaration or calling of created objects or variables
frame1 = new JFrame();
label1 = new JLabel("Hi Im label 1");
text1 = new JTextField();
button1 = new JButton("Click me!");
//action and key listener
button1.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
text1.addKeyListener(
new KeyListener(){
public void keyTyped(KeyEvent e){
}
public void keyPressed(KeyEvent e){
if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
System.exit(0);
}
}
public void keyReleased(KeyEvent e){
}
});
add(label1);
add(text1);
add(button1);
setVisible(true);
}
}
public class PracticeGUI{
public static void main(String[] args){
SwingUtilities.invokeLater(
new Runnable(){//to basically call the methods and display the created GUI; constant
public void run(){
new PracticeGUIMethods();
}
});
}
}