//Imports are listed in full to show whats being used //could - TopicsExpress



          

//Imports are listed in full to show whats being used //could just import javax.swing.* and java.awt.* etc.. import java.awt.EventQueue; import java.awt.GridLayout; import java.awt.BorderLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JButton; import java.awt.Container; public class SimpleCalc implements ActionListener{ JFrame guiFrame; JPanel buttonPanel; JTextField numberCalc; int calcOperation = 0; int currentCalc; //Note: Typically the main method will be in a //separate class. As this is a simple one class //example its all in the one class. public static void main(String[] args) { //Use the event dispatch thread for Swing components EventQueue.invokeLater(new Runnable() { @Override public void run() { new SimpleCalc(); } }); } public SimpleCalc() { guiFrame = new JFrame(); //make sure the program exits when the frame closes guiFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); guiFrame.setTitle(Simple Calculator); guiFrame.setSize(300,300); //This will center the JFrame in the middle of the screen guiFrame.setLocationRelativeTo(null); numberCalc = new JTextField(); numberCalc.setHorizontalAlignment(JTextField.RIGHT); numberCalc.setEditable(false); guiFrame.add(numberCalc, BorderLayout.NORTH); buttonPanel = new JPanel(); //Make a Grid that has three rows and four columns buttonPanel.setLayout(new GridLayout(4,3)); guiFrame.add(buttonPanel, BorderLayout.CENTER); //Add the number buttons for (int i=1;i
Posted on: Mon, 27 Jan 2014 01:44:40 +0000

Trending Topics



Recently Viewed Topics




© 2015