Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Compiling Problem


  • Please log in to reply

#1
Scyrus

Scyrus

    New Member

  • Member
  • Pip
  • 8 posts
Hey all, I've got a program that induces a frame with 2 buttons. One displays "Increment" and the other, "Decrement". The "Value: " is displayed next to it, increasing or decreasing the default value of 1 (or 0). My compiler is not working and I would like to know if any of you could tell me if it's working properly. If it's not working, what needs to be added?

import java.awt.event.*;
   import javax.swing.*;

	class ButtonPanel extends JPanel {
   
   
	  private JButton inc;
	  private JButton dec;
	  private JLabel resultLabel;
	  private int num = 1;
   	
	   public ButtonPanel(){
	  
		 resultLabel = new JLabel("Value: 1");
		  
		 inc = new JButton("Increment");
		 dec = new JButton("Decrement");
		  
		 inc.addActionListener(new ButtonsListener1());
		 dec.addActionListener(new ButtonsListener2());
		  
		 add(inc);
		 add(dec);
		 add(resultLabel);
	  }
   	
	   private class ButtonsListener1 implements ActionListener {
	  
		  public void actionPerformed (ActionEvent evt)
		 {
			num++;
			resultLabel.setText("Value: " + num);
		 }
	  }
   	
	   private class ButtonsListener2 implements ActionListener {
	  
		  public void actionPerformed (ActionEvent evt)
		 {
			num--;
			resultLabel.setText("Value: " + num);
		 }
	  }
   }

-and-

import javax.swing.*;


	public class Activity4B {
	   public static void main( String[] args ) {
		 JFrame frame = new JFrame();
		 frame.setTitle( "Increment/Decrement Valule" );
		 frame.setBounds( 300, 300, 300, 200 );
		 frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
		  
		 frame.getContentPane().add( new ButtonPane1() );
		 frame.setVisible (true);
		  
	  }
   }

  • 0

Advertisements


#2
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
ButtonPanel below is spelled with the digit '1'(one) instead of the letter 'l'

frame.getContentPane().add( new ButtonPane1() );
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP