Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Espanol
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Espanol 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 February 15th, 2005, 01:18 PM
Authorized User
 
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default error ... when calling a class

hello

 i am making a chat server program and i have made a connection dialog box which allow to make connection to the program now i want that when we click on ok button of connection dialog box , the program start so i call the class of client on the click event of ok button . please take a look below . the calling of class is mentioned in red color. please help me out if there is any mistake in the program.


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

public class Connect extends JFrame implements MouseListener{


Button buttonC = new Button("CONNECT");
TextField textField = new TextField("",0);
Button button = new Button("CANCEL");
Label label = new Label("Enetr your login name to connect to Induljin Chat",Label.CENTER);

JPanel border =new JPanel(new BorderLayout(5,5));

static final int port = 1666;
static InetAddress host;


public Connect(){




super("CONNECT DIALOG");
this.setResizable(true);
this.setDefaultCloseOperation(WindowConstants.HIDE _ON_CLOSE);
this.addMouseListener(this);


buttonC.addMouseListener(this);
button.addMouseListener(this);

//this.addWindowFocusListener(this);
this.setBackground(Color.lightGray);
buttonC.setBackground(Color.cyan);
buttonC.setForeground(Color.blue);
//textField.setEchoChar('*');
button.setBackground(Color.cyan);
button.setForeground(Color.blue);
label.setForeground(Color.blue);
border.setBackground(null);
border.setForeground(null);
border.setCursor(Cursor.getPredefinedCursor(Cursor .DEFAULT_CURSOR));
border.setFont(null);
border.add("South",textField);
border.add("West",button);
border.add("Center",label);
border.add("East",buttonC);
getContentPane().add("Center",border);

//pack();

}

//public void (WindowEvent evt){}


//public void windowLostFocus(WindowEvent evt){}









public void mouseClicked(MouseEvent evt)

 {
    if(evt.getSource()==buttonC){

    try{
    host = InetAddress.getLocalHost();


    ChatClient client = new ChatClient(host,port);
    client.start();
}
    catch(Exception e){
    e.printStackTrace();}

}
    else

    if(evt.getSource()==button){


    this.setVisible(false);
}





}

public void mouseEntered(MouseEvent evt){}


public void mouseExited(MouseEvent evt){}


public void mousePressed(MouseEvent evt){}



public void mouseReleased(MouseEvent evt){}








}

HumaMunir
__________________
HumaMunir
 
Old March 2nd, 2005, 09:13 PM
Registered User
 
Join Date: Mar 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Ancibit Send a message via Yahoo to Ancibit
Default

Why don't you try ActionListener instead? It works for buttons:
Code:
... // change your class line
public class Connect extends JFrame implements ActionListener, MouseListener {
... // change those listeners
buttonC.addActionListener(this);
button.addActionListener(this);
... // Add this somewhere:
public void actionPerformed(ActionEvent e) {

    if(e.getSource()==buttonC){

    try{        
    host = InetAddress.getLocalHost();


    ChatClient client = new ChatClient(host,port);
    client.start();
}
    catch(Exception ex){
    ex.printStackTrace();}

}
    else

    if(e.getSource()==button){
    this.setVisible(false);
}
...
As for another you might have been having, make sure to compile ChatClient before Connect.

Hope this helps ^_^

 
Old May 7th, 2005, 01:09 PM
Authorized User
 
Join Date: Dec 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks it really worked
sorry for late reply

HumaMunir





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Class within ASPX file kingroon ASP.NET 2.0 Basics 3 July 9th, 2008 07:43 AM
How to get the current calling form in a class? littlekitty ASP.NET 2.0 Basics 0 October 17th, 2006 08:28 PM
calling private method from another class jack_3 C# 3 December 16th, 2005 07:56 PM
Calling base class assignment function gstroud Visual C++ 8 September 23rd, 2004 02:33 AM
Calling SubClass attributes from parent class saravananedu Classic ASP Components 1 June 21st, 2004 01:59 AM





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