Hi Everybody, I was wondering if someone could help me figure out what is wrong with this part of my program. My program is a fraction calculator, and I'm wondering if the code I have is ok and if it will display correctly. Thanks much!!
Also should I add a button that says submit answer? and if so how would I integrate it.
public static void main(String[] args)
{
new MyNew();
}
MyNew()
{
//create panel
JPanel mainFramePanel= new JPanel(new FlowLayout());
//add action listener to buttons
startButton.addActionListener(this);
instructionsButton.addActionListener(this);
backButton.addActionListener(this);
//Adding names to JPanel
mainFramePanel.add(startButton);
mainFramePanel.add(instructionsButton);
mainFramePanel.add(backButton);
//Setting size to JPanel
mainFrame.setContentPane(mainFramePanel);
mainFrame.setSize(500,500);
mainFrame.setVisible(true);
// instructions frame
JPanel instructionsFramePanel= new JPanel(new BorderLayout());
JPanel sPane = new JPanel (new FlowLayout());
instructionsReturnButton.addActionListener(this);
instructionsFramePanel.add(instructionsReturnButton,BorderLayout.SOUTH);
instructionsFramePanel.add(instructionsText,BorderLayout.CENTER);
instructionsText.setLineWrap(true);
instructionsText.setEditable(false);
instructionsText.setWrapStyleWord(true);
instructionsText.setText("gdjklhgoshgjkdhjkdhgkjdh");
// setContent Pane and Size
instructionsFramePanel.add(sPane,BorderLayout.CENTER);
instructionsFrame.setContentPane(instructionsFramePanel);
instructionsFrame.setSize(500,500);
instructionsFrame.setVisible(false);
//numeratorOne=Integer.parseInt(inputA.getText())
//calculator
class MyNew implements ActionListener
{
JButton answerButton= new JButton("Answer");
JButton additionButton= new JButton("+");
JButton subractionButton=new JButton("-");
JButton multiplicationButton=new JButton("*");
JButton divisionButton=new JButton("/");
JButton calculatorReturnButton = new JButton ("Return");
//Frames
JFrame calculatorFrame=new JFrame();
//Labels
JLabel calculatorFrameTitle=new JLabel("Fraction Calculator");
//Text Fields
JTextField firstNumerator;
JTextField secondNumerator;
JTextField secondNumerator;
JTextField secondDenominator;
JTextField answerResults;
public static void main(String[] args)
{
new MyNew();
}
MyNew()
{
//create panel
JPanel calculatorFramePanel= new JPanel(new FlowLayout());
//Organize content pane
JPanel pane=(JPanel)getContentPane();
pane.setLayout(newBorderLayout());
//Create fields for I/O
firstNumerator=newJTextField(10);
firstDenominator=newJTextField(10);
secondNumerator=newJTextField(10);
secondDenominator=newJTextField(10);
answerResults=newJTextField(10);
answerResults.setEditable(false);
//add action listener to buttons
additionButton.addActionListener(this);
subtractionButton.addActionListener(this);
multiplicationButton.addActionListener(this);
divisonButton.addActionListener(this);
answerButton.addActionListener(this);
calculatorReturnButton.addActionListener(this);
//Adding names to JPanel
calculatorFramePanel.add(additionButton);
calculatorFramePanel.add(subtractionButton);
calculatorFramePanel.add(multiplicationButton);
calculatorFramePanel.add(divisionButton);
calculatorFramePanel.add(answerButton);
calculatorFramePanel.add(calculatorReturnButton);
//Add Labelled input fields to display
JPanel inFieldPane=newJPanel();
inFieldPane.setLayout(new GridLayout(2,2));
inFieldPane.add(newJLabel("First Numerator"));
inFieldPane.add(firstNumerator);
inFieldPane.add(newJLabel("First Denominator"));
inFieldPane.add(firstDenominator);
inFieldPane.add(newJLabel("Second Numerator"));
inFieldPane.add(secondNumerator);
inFieldPane.add(newJLabel("Second Denominator"));
inFieldPane.add(secondDenominator);
pane.add(inFieldPane,BorderLayout.NORTH);
//Add Output fields
JPanel outFieldPane=newJPanel();
outFieldPane.setLayout(newGridLayout(1,2));
outFieldPane.add(newJLabel("Answer"));
outFieldPane.add(answerResult);
pane.add(outfieldPane,BorderLayout.SOUTH);
//Display final product
pack();
setVisible(true);
}