import javax.swing.*; import java.awt.*; import java.awt.event.*; public class t
ID: 3540316 • Letter: I
Question
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class tic extends JFrame implements ActionListener {
private JTextField name;
private JButton no;
private JButton yes;
public tic() {
setLayout(null);
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
no = new JButton("No");
yes = new JButton("Yes");
name = new JTextField("Would You Like To Play?");
name.setEditable(false);
name.setBounds(80, 60, 170, 30);
no.setBounds(100, 190, 60, 30);
no.addActionListener(this);
yes.setBounds(150, 190, 60, 30);
yes.addActionListener(this);
add(no);
add(yes);
add(name);
}
public void actionPerformed(ActionEvent a) {
if(a.getSource() == no) {
System.exit(0);
}
if(a.getSource()==yes) {
setLayout(new GridLayout(4,5));
add(new JButton("1")); // want to add action listener
add(new JButton("2"));
add(new JButton("3"));
add(new JButton("4"));
add(new JButton("5"));
add(new JButton("6"));
add(new JButton("7"));
add(new JButton("8"));
add(new JButton("9"));
yes.setVisible(false);
no.setVisible(false);
}
}
}
Explanation / Answer
Hey you just need to use codes for each button like..
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
}
an you should declare the buttons as..
private javax.swing.JButton jButton1;
Rest you know buddy..
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.