The Artima Developer Community
Sponsored Link

Java Answers Forum
where i need to modify for below program ?? (java> synchronized)

3 replies on 1 page. Most recent reply: Oct 18, 2005 12:41 AM by Kondwani Mkandawire

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
jeff liew

Posts: 2
Nickname: jeffliew
Registered: Oct, 2005

where i need to modify for below program ?? (java> synchronized) Posted: Oct 15, 2005 8:57 PM
Reply to this message Reply
Advertisement
i 'm beginning for java, so pls help me ??? i doing my exersize ab the java multithread and using synchronized....can any body solve my error ???? pls
(send to my email if can >> jeffliew2001@yahoo.com)


this is my coding and this program still hv one error go out ...

******************************************************

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

public class ThreadServer {

public static void main (String arg[])
{
Studentserver frame = new Studentserver();
//frame.show();

}
}
class Studentserver extends JFrame
{
public Studentserver() {

JTextField noip, noport, namapeniaga, nokp, alamatp, notepon, lokasi,tarikhguna,tarikhtempah;
String ip,nport,lok,namap, kp, alam,tpon,tguna,ttempah;
JTextArea data;
JScrollPane pane;
JButton save;
setTitle( "Student Registration" ) ;
Container con = this.getContentPane();
con.setLayout(new GridLayout(1,10));
JPanel grid = new JPanel(new GridLayout(4,5));
JPanel lowerPanel = new JPanel (new FlowLayout());

this.setSize(700,400);

this.setVisible(true);
this.setLocation(120,10);
JLabel label = new JLabel("", SwingConstants.CENTER);
label.setForeground(Color.blue);
grid.add(new JLabel("Student Registration Form",SwingConstants.CENTER));
label.setFont(new Font("Britannic Bold",Font.BOLD,20));
con.add(label);
data = new JTextArea(50,50);
data.setEditable(false);
pane = new JScrollPane();
pane.setViewportView(data);
grid.add(new JLabel("Information Student ",SwingConstants.CENTER));
grid.add(data);
grid.add(new JLabel("",SwingConstants.CENTER));
con.add(grid);
save = new JButton("Save");
lowerPanel.add(save);
con.add(lowerPanel);
save.addActionListener(new ActionListener(){
public void actionPerformed (ActionEvent e)
{
JButton save;
JTextArea data;

if(e.getSource() == save)
{
String file = data.getText();
saveLog(file);
Thread t1=new Thread1();
t1.start();
}
}
});
}
}
class Thread1 extends Thread
{

public Thread1()
{
Thread notificationThread=new Thread1();
notificationThread.start();

synchronized(notificationThread)
{
notificationThread.wait();
}
System.out.println("The wait is over");
}

public void run()
{
try
{
JTextField noip, noport, namapeniaga, nokp, alamatp, notepon, lokasi,tarikhguna,tarikhtempah;
String ip,nport,lok,namap, kp, alam,tpon,tguna,ttempah;
JTextArea data;
JScrollPane pane;
JButton save;

int port = 400;
//open socket
ServerSocket server = new ServerSocket(port);
while(true)
{
Socket rcv_client = server.accept();

DataInputStream dataIn = new DataInputStream(rcv_client.getInputStream());

String course = dataIn.readUTF();
String name= dataIn.readUTF();
String matrik= dataIn.readUTF();
String birth = dataIn.readUTF();
String ic = dataIn.readUTF();
String address = dataIn.readUTF();

InetAddress destination =rcv_client.getInetAddress();
int eport=rcv_client.getPort();

//data.append("\n");
data.append("Received from "+rcv_client.getInetAddress());
data.append("\n with port "+rcv_client.getPort());
data.append("\n Your course : "+ course);
data.append("\n Name : "+ name);
data.append("\n Matrix Number : "+ matrik);
data.append("\n Address : "+ address);
data.append("\n Birth date: "+ birth);
data.append("\n I/C Number : "+ ic);
data.append("\n Your information is succeful store in database ");
data.append("\n Information will be give to "+rcv_client.getInetAddress());
data.append("");

DataOutputStream dataOut = new DataOutputStream(rcv_client.getOutputStream());
dataOut.flush();
}

//this.addWindowListener(new WindowAdapter()
//{
//public void windowClosing(WindowEvent event){
//System.exit(0);
//}

//});

}
catch(BindException bind){
System.out.println("Bind Error:"+bind);
}

catch(IOException io){
System.out.println("IO Error:"+io);
}

synchronized (this)
{
this.notify();
}
}
public void saveLog(String file){
try
{
JOptionPane.showMessageDialog(null,"Information is save ","System Information",JOptionPane.INFORMATION_MESSAGE);

FileWriter write = new FileWriter("Database.txt", true);
PrintWriter text = new PrintWriter(write);

text.println("\n" + file);
text.flush();
text.close();
}
catch (IOException ioerr)
{
JOptionPane.showMessageDialog(null,"IO error: " + ioerr,"Error!",JOptionPane.ERROR_MESSAGE);
}

}
}


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: where i need to modify for below program ?? (java> synchronized) Posted: Oct 17, 2005 12:57 AM
Reply to this message Reply
1. Reformat your code using the java tag as shown in the "formatting your post" section.

2. What is the purpose of the program?

3. Wich error do you get?

jeff liew

Posts: 2
Nickname: jeffliew
Registered: Oct, 2005

Re: where i need to modify for below program ?? (java> synchronized) Posted: Oct 18, 2005 12:04 AM
Reply to this message Reply
Below is the error for my system ......


C:\Documents and Settings\liew\Desktop\Multithread test\ThreadServer.java:71: cannot find symbol
symbol: method saveLog(java.lang.String)
saveLog(file);
^
here is the code
if(e.getSource() == save)
{
String file = data.getText();
saveLog(file);
Thread t1=new Thread1();
t1.start();
}
}

actually i put all the program is , beside the error come out, i think my program still got another error if the upper one if solve .....can u all tell me why like that as soon as possible ...pls .....

Kondwani Mkandawire

Posts: 530
Nickname: spike
Registered: Aug, 2004

Re: where i need to modify for below program ?? (java> synchronized) Posted: Oct 18, 2005 12:41 AM
Reply to this message Reply
Suggestions:

1) Get your head checked coz you can't seem to follow instructions.
(Matthias had asked you to reformat your code and you chose to ignore
that).
2) Either take up ESL (English as a Second Language) or find a Java
forum whose medium of communication is in your venacular (your mother
tougue). I'm not trying to be a wise guy, but clearly you have
problems expressing yourself in English - I definitely have a
problem trying to understand what it is you are trying to say.

Flat View: This topic has 3 replies on 1 page
Topic: How to add a property listener for variable Previous Topic   Next Topic Topic: Class Conversion problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use