2 Comp ete the program based on the given comments. The program uses two to disp
ID: 3807982 • Letter: 2
Question
2 Comp ete the program based on the given comments. The program uses two to display messages on the console. (16 points) buttons public class of JButton with label "ok" JFrame //create an instance //create an instance of JButton with label Cancel Public TestButton JPanel panel new JPanel //add the OK button to Panel //add the Cancel button to panel this add (panel) //add oKListener to or button //add cancellistener to cancel button public static void main (String args) Test Button app new Test Button App .set visible (true)Explanation / Answer
Public class testbutton extends Jframe{
Jframe f = new Jframe();
Button okbutton = new Button("ok");
Button cancelbutton = new Button("cancel");
Public testbutton()
{
Jpanel panel = new Jpanel();
panel.add(okbutton);
panel.add(cancelbutton);
this.add(panel);
okbutton.addActionListner(new ActionListner());
cancelbutton.addActionListner(new ActionListner());
}
Public static void main(string []args)
{
Testbutton app = new Testbutton();
App.setvisible(true);
}
Class oklistner implements ActionListner{
Public void actionperformed(Actionevent e) {
JDialog d = new JDialog(f,"ok button clicked",true);
d.setLocationRelativeTo(f);
d.setVisible(true);
}
}
Class cancelListner implements ActionListner{
Public void actionperformed(Actionevent e) {
JDialog e = new JDialog(f,"cancel button clicked",true);
e.setLocationRelativeTo(f);
e.setVisible(true);
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.