Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Program is not displaying the number of clicks

  1. #1
    MW130 is offline Senior Member
    Join Date
    Jan 2013
    Rep Power

    Default Program is not displaying the number of clicks

    Hi I am trying to make a swing program to display the number of clicks. The program pops up, and once clicked, responds with "clicked", which is good. What is not working is that I want it to say how MANY times it has been clicked. I think maybe it is working but it is not being displayed because the button is on the pane and the graphics method isn't? How would I add the line that broadcasts how many times it's been clicked to the content pane? Thanks, and here's the code.
    Java Code:
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class JCode implements ActionListener {
    	JButton button;
    	int click = 0;
    	public void go() {
    		JFrame frame = new JFrame("EVENT HANDLING");
    		frame.setSize(500, 500);
    		button = new JButton("Click me");
    	public static void main(String[] args) {
    		JCode runIt = new JCode();
    	public void paint(Graphics g) {
    		g.drawString("This is an actionListener.", 20, 50);
    		g.drawString("This has been clicked: " + click, 20, 100);
    	public void actionPerformed(ActionEvent event) {

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

Similar Threads

  1. Differentiating user clicks and doClick clicks?
    By jiffi in forum New To Java
    Replies: 19
    Last Post: 01-13-2012, 08:30 AM
  2. Think of a number Program
    By andnlou2678 in forum New To Java
    Replies: 21
    Last Post: 11-18-2011, 08:07 AM
  3. displaying prime number
    By eng_hyzoom in forum New To Java
    Replies: 1
    Last Post: 11-26-2010, 11:21 AM
  4. Phone number Program ..
    By Sary in forum New To Java
    Replies: 9
    Last Post: 03-17-2010, 07:15 PM
  5. code for number of clicks clicked on a web page???
    By Sveta_cool in forum Advanced Java
    Replies: 2
    Last Post: 02-01-2008, 02:55 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts