Somebody help me, i'm a beginners of the java language, but in my interested to learn a java. and I create a GUI but the MDAS formula is not there, it because i dont know how to solve that, it cause need a pop and post function for the Calculator program.
///runner.java
import javax.swing.JFrame;
public class runner {
public static void main(String args[]){
JFrame lor = new JFrame();
cal rece = new cal();
lor = rece.buildNewFrame();
lor.pack();
lor.setVisible(true);
}
}
/////cal.java
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class cal {
JLabel expression1 = new JLabel("Expression:");
JLabel result1 = new JLabel("Result: ");
JTextField expression_textf1 = new JTextField(30);
JTextField result_textf1 = new JTextField(10);
JButton clear1 = new JButton(" Clear ");
JButton calculate1 = new JButton(" Calculate");
JButton cancel1 = new JButton(" Cancel");
public JPanel gui_2() {
JPanel northPanel1 = new JPanel();
JPanel northPanel2 = new JPanel();
northPanel1.setLayout(new GridLayout(2, 0));
northPanel1.add(expression1);
northPanel1.add(expression_textf1);
northPanel1.add(result1);
northPanel1.add(result_textf1);
northPanel2.setLayout(new FlowLayout(FlowLayout.CENTER));
northPanel2.add(northPanel1);
return northPanel2;
}
public JPanel gui_3() {
JPanel southPanel1 = new JPanel();
JPanel southPanel2 = new JPanel();
southPanel1.setLayout(new GridLayout(2, 2));
southPanel2.add(calculate1);
southPanel2.add(clear1);
southPanel2.add(cancel1);
southPanel2.setLayout(new FlowLayout(FlowLayout.CENTER));
southPanel2.add(southPanel1);
return southPanel2;
}
public JFrame buildNewFrame() {
try{
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){}
cal re = new cal();
JPanel northPanel = new JPanel();
JPanel southPanel = new JPanel();
JPanel finalPanel = new JPanel();
northPanel = re.gui_2 ();
southPanel = re.gui_3 ();
finalPanel.setLayout( new BorderLayout());
finalPanel.add(northPanel, BorderLayout.NORTH);
finalPanel.add(southPanel, BorderLayout.SOUTH);
JFrame frame = new JFrame("CALCULATOR IN PRELIM DEPENDS");
frame.setSize(900, 900);
frame.getContentPane().add(finalPanel);
frame.addWindowListener( new WindowAdapter()
{
public void windowClosing( WindowEvent e) {
System.exit(0);
}
});
return frame;
}
}