Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
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