import java.awt.BorderLayout;//Just some imports that are neededimport java.awt.GridLayout;//Just some imports that are neededimport java.awt.event.ActionEvent;//Just some imports that are neededimport java.awt.event.ActionListener;//Just some imports that are neededimport javax.swing.BorderFactory;//Just some imports that are neededimport javax.swing.JButton;//Just some imports that are neededimport javax.swing.JFrame;//Just some imports that are neededimport javax.swing.JLabel;//Just some imports that are neededimport javax.swing.JPanel;//Just some imports that are neededpublicclassGUI implements ActionListener{//If there is a red line after writing GUI its cause you have no code for the bit that's after implements so just hover over gui and just press "add unimplemented methods"int count =0;//a VAR for the function of the button for the number of clicksprivate JLabel label;
private JPanel panel;
private JFrame frame;
publicGUI(){//This implements for the constructor that is being create in the void main, Here you can make frames for the gooooooey and define its characteristics :P//JFrame - we have removed this from the line below to make a var that we can use in multiple methods {a}
frame =newJFrame();//This sets the frame for the goooooooooey so the user can customise it to their needs
JButton button =newJButton("Howdy");//This is used to make a button
button.addActionListener(this);//This refers to the class that we are using like GUI implements Action listener//JLabel {a}
label =newJLabel("Number of clicks: 0"); //This is used to add a label to our program//JPanel {a}
panel =newJPanel();//This sets the panel for the gooey for the user so that they can add elements, delete import etc etc
panel.setBorder(BorderFactory.createEmptyBorder(30,30,10,30));//This makes a border object for the goooey and the number in the field describes the distance it should be from the borders of the gui
panel.setLayout(newGridLayout(0,1));// This is the default constructor for the borders/grids
panel.add(button);//This adds the button ( basically packing like btn.pack())
panel.add(label);//This adds the button (packs)
frame.add(panel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Our GOOEY");//sets the title
frame.pack();//like py
frame.setVisible(true);//kinda literal this just lets the dev choose if the user can see this or not
}
publicstaticvoidmain(String[] args) {
newGUI();//Creates a constructor but this needs to be implemented to actually show us the gui window
}
@Override
publicvoidactionPerformed(ActionEvent e) {//After implementing the unimplemented methods this autogenerated method is initiated to help us write our code in for the action we need to perform
count++;//Increases the count by 1
label.setText("Number of clicks: "+ count);//This just changes the text of the label like lable.config("Hey") and then adds the number of clicks to the string
}
}
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems
resetting your password contact us
Check Your Email and Click on the link sent to your email