Here are the two classes I'm using. It's a very simple program I made just to learn the Swing syntax and stuff.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class WindowsApp extends JFrame{
private static final long serialVersionUID = 1L;
JPanel mainWindow;
JPanel buttonPanel;
JButton btnEnter;
JButton btnExit;
JTextField txtInput;
JLabel lblDisplay;
String strInput;
public WindowsApp(){
mainWindow = new JPanel();
buttonPanel = new JPanel();
btnEnter = new JButton();
btnExit = new JButton();
txtInput = new JTextField();
lblDisplay = new JLabel();
buttonPanel.setVisible(true);
btnEnter.setText("Enter");
btnEnter.setVisible(true);
btnExit.setText("Exit");
btnEnter.setVisible(true);
txtInput.setText("Please enter a string");
txtInput.setVisible(true);
lblDisplay.setText("");
lblDisplay.setVisible(true);
mainWindow.setLayout(new BorderLayout());
add(txtInput, BorderLayout.NORTH);
add(lblDisplay, BorderLayout.SOUTH);
add(buttonPanel, BorderLayout.CENTER);
buttonPanel.setLayout(new GridLayout(2,1));
buttonPanel.add(btnEnter);
buttonPanel.add(btnExit);
btnEnter.addActionListener(new BHandlerENTER());
btnExit.addActionListener(new BHandlerExit());
this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
private void changeText(){
lblDisplay.setText(strInput);
}
private void readText(){
strInput = txtInput.getText();
}
private void close(){
this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
class BHandlerENTER implements ActionListener{
public void actionPerformed(ActionEvent e){
readText();
changeText();
}
}
class BHandlerExit implements ActionListener{
public void actionPerformed(ActionEvent e){
close();
}
}
}
AND:
public class Main {
public static void main(String [] args){
WindowsApp winni = new WindowsApp();
winni.setTitle("Yea bitch!");
winni.setSize(200,150);
winni.pack();
winni.setLocation(400,500);
winni.setVisible(true);
winni.setResizable(false);
}
}