Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 27th, 2003, 11:35 AM
Authorized User
 
Join Date: Aug 2003
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);
  }
}

 
Old August 28th, 2003, 01:22 AM
Authorized User
 
Join Date: May 2003
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.