import javax.swing.*;
//Loads the Swing Components which contains the Jframe and others
import java.awt.*;
//Loads AWT which contains the container and Listener if you like to use buttons
//Global Declarations
private JLabel A = new Jbutton();
//adding extends & implements enable the use of Jframe and Action Listeners
public class Main extends JFrame implements ActionListener{
JFrame Samp = new JFrame();
Samp.setTitle("This is my Program"); //Set the Title
Samp.setBounds(100, 100, 800, 600); //(set the location and size)
Samp.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Samp.setVisible(true); //This will open your Gui
Container container = this.getContentPane(); //set a container
// From this on you can add buttons, textfields, etc to the container
container.setLayout(null);
//setting it to null but you can use other layouts on this
//Example of adding a button
Jbutton A = new Jbutton("Compute Quantity");
A.addActionListener(this); //adds a listener
A.setBounds(x,y,Width,Ht); //This are in pixels, set the location
container.add(A); // finally adds the button to the container
//Example of adding a label
A.setText("Output Here");
A.addActionListener(this); //adds a listener
A.setBounds(x,y,Width,Ht); //This are in pixels, set the location
container.add(A); // finally adds the button to the container
//Add more components here see tutorials for other components =)
}
//Here is were the action listener awaits =)
public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if(command.equalsIgnoreCase("Compute Quantity")){
//Quantity equation here
//Display the output to a textfield/Label/TextArea
A.setText(Output Here); //Change the display of A (Jlabel)
} else if (command.equalsIgnoreCase("Other buttons")){
} else if (command.equalsIgnoreCase("Other buttons2")){
}
}
}