StringBuilder/ActionEvent help!
I am new to Java and am trying to create a program that uses GridLayout, panels, has 2 labels and buttons across the top to enter a starting and end number, a button in the center to make the program calculate all of the numbers divisible by 2, and a display box centered at the bottom that uses scroll bars when necessary to display all the numbers divisible by 2 within the user defined range.
Below is my code. I would appreciate some help resolving the errors. I am not sure what I did wrong or how to solve these errors at all. I am required to use StringBuilder, setText(), and toString(). Thank you in advance for any pointers and advice on this!!
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class DivisibleByTwoGUI extends JFrame implements ActionListener{
private final int HEIGHT = 450;
private final int WIDTH = 600;
private JLabel lblStartNum, lblEndNum, lblBlank;
private JTextField txtStartNum, txtEndNum;
private JButton btnShow;
private JScrollPane scrollResults;
private JTextArea txtareaResults;
private JPanel p1, p2, p3, p4;
private String start, end;
private int startInt, endInt;
public DivisibleByTwoGUI(String title){
super(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(HEIGHT, WIDTH);
setLayout(new GridLayout(1,1));
p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
p4 = new JPanel();
p1.setLayout(new GridLayout(3,1));
p2.setLayout(new FlowLayout());
p3.setLayout(new GridLayout(1,3));
p4.setLayout(new GridLayout(1,3));
p2.add(p1);
p3.add(p1);
p4.add(p1);
add(p1);
p2.add(lblStartNum);
p2.add(txtStartNum);
p2.add(lblEndNum);
p2.add(txtEndNum);
p3.add(lblBlank);
p3.add(btnShow);
p3.add(lblBlank);
txtareaResults = new JTextArea(5,30);
txtareaResults.setEditable(false);
scrollResults = new JScrollPane(txtareaResults);
p4.add(lblBlank);
p4.add(scrollResults);
p4.add(lblBlank);
btnShow = new JButton("Show numbers divisible by 2");
btnShow.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
StringBuilder str = new StringBuilder();
if(event.getSource() == btnShow){
String start = txtStartNum.getText();
String end = txtEndNum.getText();
startInt = Integer.parseInt(start);
endInt = Integer.parseInt(end);
if(StartInt <= EndInt){
StartInt = StartInt + EndInt;
EndInt = StartInt - EndInt;
StartInt = StartInt - EndInt;
}
while(StartInt <= EndInt){
if(StartInt % 2 == 0){
str.append(StartInt + "\n");
StartInt++;
}
}
}
txtareaResults.setText(str.toString());
}
}
----------------------------------------------------------------------
Below is seperate code to test with:
public class DivisibleByTwoGUITest{
public static void main(String[] args){
DivisibleByTwoGUI screen = new DivisibleByTwoGUI("Divisible by Two");
screen.setSize(600,450);
screen.setVisible(true);
}
}