Howdy, I am working on my GUI skills, seeming how they are lacking and decided to make a project to get them better. The objective of my code is to allow the user to select from 1 of four patterns, and the user could input any character and that would be what the pattern would consist of. However, nothing seems to have gone right, and I would appreciate the help.
p.s - I know the patterns are the same, I just left them the same to test, and it wouldn't work.
p.s - I know the patterns are the same, I just left them the same to test, and it wouldn't work.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PracticeProgram extends JFrame
{
//Declare your variables
private JLabel pattern_one, pattern_two, pattern_three, pattern_four;
private JTextField character_input, triangle_output;
private JButton p_1, p_2, p_3, p_4, clear;
private PatternOneHandler p1Handler;
private PatternTwoHandler p2Handler;
private PatternThreeHandler p3Handler;
private PatternFourHandler p4Handler;
/*private RandomButtonHandler rbHandler;*/
private ClearButtonHandler cbHandler;
/*private ExitButtonHandler ebHandler;*/
private static final int WIDTH = 800;
private static final int HEIGHT = 800;
public PracticeProgram()
{
// Labels
pattern_one = new JLabel("Pattern One", SwingConstants.CENTER);
pattern_two = new JLabel("Pattern Two", SwingConstants.CENTER);
pattern_three = new JLabel("Pattern Four", SwingConstants.CENTER);
pattern_four = new JLabel("Pattern Five", SwingConstants.CENTER);
// TextFields
character_input = new JTextField(1);
trianle_output = new JTextField(100);
// Buttons
p_1 = new JButton("1");
p_2 = new JButton("2");
p_3 = new JButton("3");
p_4 = new JButton("4");
/*random = new JButton("Random");*/
clear = new JButton("Clear");
/*exit = new JButton("exit");*/
// Handlers
p1Handler = PatternOneHandler();
p2Handler = PatternTwoHandler();
p3Handler = PatternThreeHandler();
p4Handler = PatternFourHandler();
/*rbHandler = RandomButtonHandler();*/
cbHandler = ClearButtonHandler();
/*ebHandler = ExitButtonHandler();*/
// ActionListeners
p_1.addActionListener(p1Handler);
p_2.addActionListener(p2Handler);
p_3.addActionListener(p3Handler);
p_4.addActionListener(p4Handler);
/*random.addActionListener(rbHandler);*/
clear.addActionListener(cbHandler);
/*exit.addActionListener(ebHandler);*/
// Set Title
setTitle("Review");
//Container
Container pane = getContentPane();
//Layout
pane.setLayout(new GridLayout(2, 7));
//Add to your container
pane.add(pattern_one);
pane.add(p_1);
pane.add(pattern_two);
pane.add(p_2);
pane.add(pattern_three);
pane.add(p_3);
pane.add(pattern_four);
pane.add(p_4);
/*pane.add(random);*/
pane.add(clear);
/*pane.add(exit);*/
//Set Size
setSize(WIDTH, HEIGHT);
//Make Visible
setVisible(true);
//Default close operation
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class p1Handler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
char symbol = character_input.getText().charAt(0);
for(int row = 0; row < 10; row++)
{
for(int col = 0; col <= row; col++)
{
triangle_output.setText("" + symbol);
}
triangle_output.append("\n");
}
}
}
private class p2Handler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
char symbol = character_input.getText().charAt(0);
for(int row = 0; row < 10; row++)
{
for(int col = 0; col <= row; col++)
{
triangle_output.setText("" + symbol);
}
triangle_output.append("\n");
}
}
}
private class p3Handler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
char symbol = character_input.getText().charAt(0);
for(int row = 0; row < 10; row++)
{
for(int col = 0; col <= row; col++)
{
triangle_output.setText("" + symbol);
}
triangle_output.append("\n");
}
}
}
private class p4Handler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
char symbol = character_input.getText().charAt(0);
for(int row = 0; row < 10; row++)
{
for(int col = 0; col <= row; col++)
{
triangle_output.setText("" + symbol);
}
triangle_output.append("\n");
}
}
}
/*private class rbHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}*/
private class cbHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
triangle_output.setText("");
}
}
/*private class ebHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}*/
public static void main(String[] args)
{
PracticeProgram practProgram = new PracticeProgram();
}
}