Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 27th, 2003, 11:35 AM
Authorized User
 
Join Date: Aug 2003
Location: , , Ghana.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to egolileopablo Send a message via Yahoo to egolileopablo
Default How to write events

this is a sample . i want to click and it gives me number of times clicked.

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
//import javax.swing.event;

public class Beep extends JFrame implements ActionListener {

  JButton btn;
  public static final int ACTION_FIRST;

  public Beep() {
    super("Try");

    Container c = getContentPane();
    c.setLayout(new BorderLayout());

    btn = new JButton(ACTION_FIRST);
    btn.setLayout(new FlowLayout());
    btn.setActionCommand("Prees");
    btn.addActionListener(this);
    c.add(btn, BorderLayout.SOUTH);

    setSize(200,200);
    setVisible(true);

  }

  public void actionPerformed(ActionEvent e) {
      str = "ACTION";
    str = btn.getActionCommand();
  }

  public static void main(String args[]) {
    Beep beep = new Beep();
    beep.setDefaultCloseOperation(EXIT_ON_CLOSE);
  }
}

Reply With Quote
  #2 (permalink)  
Old August 28th, 2003, 01:22 AM
Authorized User
 
Join Date: May 2003
Location: New Delhi, Delhi, India.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

I have made changes in your code just go through it

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
//import javax.swing.event;

public class Beep extends JFrame implements ActionListener {

  JButton btn;
  public static int ACTION_FIRST=0;

  public Beep() {
    super("Try");

    Container c = getContentPane();
    c.setLayout(new BorderLayout());

    btn = new JButton("Click");
    btn.setLayout(new FlowLayout());
    btn.setActionCommand("Prees");
    btn.addActionListener(this);
    c.add(btn, BorderLayout.SOUTH);

    setSize(200,200);
    setVisible(true);

  }

  public void actionPerformed(ActionEvent e) {
    if(e.getSource()== btn)
    {
        ACTION_FIRST+=1;
        System.out.println("Button Clicked " + ACTION_FIRST + " Times");
    }

  }

  public static void main(String args[]) {
    Beep beep = new Beep();
    beep.setDefaultCloseOperation(EXIT_ON_CLOSE);
  }
}

Regards

Yashraj Chauhan
Java\J2EE Specialist
Wiley Support Team
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between Trace.write and Debug.write surendraparashar ASP.NET 2.0 Professional 1 June 27th, 2007 02:12 AM
Events bschleusner C# 2005 2 February 26th, 2007 05:25 AM
Events not firing in IE malk ASP.NET 1.0 and 1.1 Professional 7 August 29th, 2006 01:32 PM
help with Events egiblock JSP Basics 0 October 6th, 2003 11:39 PM



All times are GMT -4. The time now is 05:50 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.