This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance 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); }

public void actionPerformed(ActionEvent ae) {
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
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