Total members 10261 | Gratitudes |It is currently Tue May 22, 2012 5:39 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: applet in netbeans
PostPosted: Thu Dec 30, 2010 2:50 am 
Offline
Newbie
User avatar

Joined: Wed Dec 15, 2010 11:41 pm
Posts: 2
Has thanked: 0 time
Have thanks: 0 time

:hi: all i have a java client applet and i know that the applet has no main()
class and when try to run it with netbeans , a message ( no main class found )
how i can run the applet or how i can convert it to application?
What exactly must I do to make the program works, knowing that I want to work between two computers, one Chat server and the other is client.

Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
public class Client extends Panel implements Runnable
{
// Components for the visual display of the chat windows
private TextField tf = new TextField();
private TextArea ta = new TextArea();
// The socket connecting us to the server
private Socket socket;
// The streams we communicate to the server; these come
// from the socket
private DataOutputStream dout;
private DataInputStream din;
// Constructor
public Client( String host, int port ) {// Set up the screen
setLayout( new BorderLayout() );
add( "North", tf );
add( "Center", ta );
// We want to receive messages when someone types a line
// and hits return, using an anonymous class as
// a callback
tf.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
processMessage( e.getActionCommand() );
}
} );
// Connect to the server
try {
// Initiate the connection
socket = new Socket( host, port );
// We got a connection! Tell the world
System.out.println( "connected to "+socket );
// Let's grab the streams and create DataInput/Output streams
// from them
din = new DataInputStream( socket.getInputStream() );
dout = new DataOutputStream( socket.getOutputStream() );
// Start a background thread for receiving messages
new Thread( this ).start();
} catch( IOException ie ) { System.out.println( ie ); }
}
// Gets called when the user types something
private void processMessage( String message ) {
try {
// Send it to the server
dout.writeUTF( message );
// Clear out text input field
tf.setText( "" );
} catch( IOException ie ) { System.out.println( ie ); }
}
// Background thread runs this: show messages from other window
public void run() {
try {
// Receive messages one-by-one, forever
while (true) {
// Get the next message
String message = din.readUTF();
// Print it to our text window
ta.append( message+"\n" );
}
} catch( IOException ie ) { System.out.println( ie ); }
}
}



Code:
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.net.*;
public class ClientApplet extends Applet
{
public void init() {
String host = getParameter( "host" );
int port = Integer.parseInt( getParameter( "port" ) );
setLayout( new BorderLayout() );
add( "Center", new Client( host, port ) );
}
}




thx all .


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 Java applet
 i am using NetBeans 7.0, HELP NEEDED - URGENT
 Des java Applet ( Data Encryption Standards )
 JFrame properties for an Applet to be embedded in website?
 information about netbeans IDE
 Data Base problem with Netbeans IDE
 chat system project in java using netbeans
 copy files from applet server to client
 selection of checkbox in buttongroup in netbeans
 Snake 2D {Applet}

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 3 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team