This is a two part question that is pretty simple and that is why the points are
ID: 3547006 • Letter: T
Question
This is a two part question that is pretty simple and that is why the points are so low.
2. A.
Write an application that instantiates a JFrame that contains a JButton. Disbale the JButton after the user clicks it. Save as JFrameDisableButton.java.
2.B.
Modify the JFrameDisableButton program so that the JButton is not disabled untilthe user has clicked at least 8 times. At that point display a JLabel that indicates "That's enough!". Save the file as JFrameDisabledButton2.java
***SIDE NOTE***
Please make sure you dont use expert code because this is my first java class and I cannot use anything past chapter 14 so everything from chapter 1 all the way up to 14 can be used but nothing futher then that. Please answer both parts so I may award the points to you.
Explanation / Answer
########################PART A####################
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class JFrameDisabledButton extends JFrame{
private JButton enterJButton;
private Container contentPane;
/**
* @param args
*/
public JFrameDisabledButton() {
createUserInterface();
}
private void createUserInterface() {
contentPane = getContentPane();
contentPane.setLayout(null);
enterJButton = new JButton();
enterJButton.setBounds(400, 420, 80, 30);
enterJButton.setText("Enter");
contentPane.add(enterJButton);
enterJButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
enterJButtonActionPerformed(event);
}
});
setTitle("Button Click");
setSize(500, 500);
setVisible(true);
}
private void enterJButtonActionPerformed(ActionEvent event) {
enterJButton.setEnabled(false);
}
public static void main(String[] args) {
JFrameDisabledButton b=new JFrameDisabledButton();
b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.