Topic: 大虾帮忙 (setDefaultCloseOPeration 调不出来)

  Print this page

1.大虾帮忙 (setDefaultCloseOPeration 调不出来) Copy to clipboard
Posted by: ulo_88
Posted on: 2004-11-07 23:44


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

public class Server {
private JTextField ft;
private JTextArea display;
private ObjectOutputStream output;
private ObjectInputStream input;
private ServerSocket server;
private Socket connection;
private int Counter=1;

public Server() {
super("server");
Container conainer= getContentPane();
ft= new JTextField();
ft.setEnabled(false);
ft.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent event){
sendData(event.getActionCommand());
}
});
conainer.add(ft,BorderLayout.NORTH);
display = new JTextArea();
conainer.add(new JScrollPane(display),BorderLayout.CENTER);
setSize(300,150);
setVisible(true);
}
public void runSrever(){
try{
server = new ServerSocket(5000,100);
while(true){
waitForConnection();
getStreams();
processConnection();
closeConncetion();
++Counter;
}
}
catch(EOFException eofException){
System.out.println("Client terminbate conncetion");
}
catch(IOException ioException){
ioException.printStackTrace();
}
}
private void waitForConnection() throws IOException{
display.setText("Waiting for conncetion");
connection = server.accept();
display.append("Conncetion "+ Counter +" received form "+connection.getInetAddress().getHostName());

}
public void getStreams() throws IOException{
output=new ObjectOutputStream(connection.getOutputStream());
output.flush();
input = new ObjectInputStream(connection.getInputStream());
display.append("\nGot I/O streams");
}
public void processConnection() throws IOException{
String message="SERVER>>>Conncetion succesful";
output.writeObject(message);
output.flush();
do{
try{
message=(String)input.readObject();
display.append("\n"+message);
display.setCaretPosition(display.getText().length());
}
catch(ClassNotFoundException classe){
display.append("\nUnknown onject type received");
}
}while(!message.equals("CLEENT>>>TERMINATE"));
}
public void closeConncetion()throws IOException{
display.append("\nUser termainate connttion");
ft.setEditable(false);
output.close();
input.close();
connection.close();
}
public void sendData(String message){
try{
output.writeObject("SERVER>>>"+message);
output.flush();
display.append("\nSERVER>>>"+message);

}
catch(IOException ioExcetion){
display.append("\nException writing object");
}
}
public static void main(String args[]){
Server application = new Server();
application.setDefaultCloseOPeration(JFrame.EXIT_ON_CLOSE);
application.runSrever();
}
}


setDefaultCloseOPeration这个方法 调不出来

2.Re:大虾帮忙 [Re: ulo_88] Copy to clipboard
Posted by: ulo_88
Posted on: 2004-11-07 23:50

本小虾初学 谢谢各位大虾帮忙 错误信息

"Server.java": cannot resolve symbol: method setDefaultCloseOPeration (int)in class untitled1.Server at line 107, column 17
"Server.java": cannot resolve symbol: method setVisible (boolean)in class untitled1.Server at line 40, column 5
"Server.java": cannot resolve symbol: method setSize (int,int)in class untitled1.Server at line 39, column 5
"Server.java": cannot resolve symbol: method getContentPane ()in class untitled1.Server at line 28, column 25
"Server.java": Object() in java.lang.Object cannot be applied to (java.lang.String) at line 27, column 5

3.Re:大虾帮忙 (setDefaultCloseOPeration 调不出来) [Re: ulo_88] Copy to clipboard
Posted by: why
Posted on: 2004-11-08 20:46

请尽量用准确的文字描述作为标题
Applet,AWT,Swing的问题请移步至Java GUI


1. public class Server extends JFrame

2. application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

请先好好打稳基础才碰GUI方面的技术!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923