Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To Michael Ernest -about changing button labels

 
Avin Sinanan
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok i tried the code but it didn't compile.. and you told me to notify you if it didn't...
here is the code.. thanks for the help so far

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonThing implements ActionListener
{ private JPanel jp;
private JButton jb;
private JLabel jl;
private JFrame jf ;

private int presses = 0; public ButtonThing(String title) {
jf = new JFrame(title);
jp = new JPanel(new BorderLayout());
jb = new JButton("Click Me");
jl = new JLabel();
jp.add(jb, BorderLayout.NORTH);
jp.add(jl, BorderLayout.SOUTH);

jf.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0); }
});
jf.setContentPane(jp);
jf.setSize(250,250);
jf.setVisible(true);
}

public void actionPerformed(ActionEvent ae) {
++presses;
jb.setLabel("Thank you for clicking");
jl.setText("Press count: " + presses);
}
public static void main(String args[]) {
// Run program with:
// java ButtonThing
ButtonThing bt = new ButtonThing(args[0]);
}
}

if u can fix this please do.. you help would be greatly appreciated.. yours respectful Avin Sinanan
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, sure, but help me out here just a little! What compiler errors did you get?
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic