java GUI求解 源代码如下,求用GUI修改输入输出介面。
//Forusewithexercise2.2.importjava.io.*;importjava.net.*;importjava.util.*;publicclas...
//For use with exercise 2.2.
import java.io.*;
import java.net.*;
import java.util.*;
public class EmailClient
{
private static InetAddress host;
private static final int PORT = 1234;
private static String name;
private static Scanner networkInput, userEntry;
private static PrintWriter networkOutput;
private static BufferedReader in;
public static void main(String[] args) throws IOException
{
try
{
host = InetAddress.getLocalHost();
}
catch(UnknownHostException uhEx)
{
System.out.println("Host ID not found!");
System.exit(1);
}
userEntry = new Scanner(System.in);
do
{
System.out.print("\nEnter name ('Dave' or 'Karen'): ");
name = userEntry.nextLine();
}while (!name.equals("Dave") && !name.equals("Karen"));
talkToServer();
}
private static void talkToServer() throws IOException
{
String option, message, response;
do
{
Socket link = new Socket(host,PORT);
in = new BufferedReader(new InputStreamReader(link.getInputStream()));
networkOutput = new PrintWriter(link.getOutputStream(),true);
do
{
System.out.print("\nEnter option 'send' or 'read':");
option = userEntry.nextLine();
}while (!option.equals("send") && !option.equals("read"));
if (option.equals("send"))
doSend();
else
doRead();
link.close();
System.out.print("\nDo you want to send/read again? (y/n) : ");
option = userEntry.nextLine();
}while (!option.equals("n"));
}
private static void doSend() throws IOException
{
System.out.println("\nEnter 1-line message: ");
String message = userEntry.nextLine();
networkOutput.println(name);
networkOutput.println("send");
networkOutput.println(message);
}
private static void doRead() throws IOException
{
networkOutput.println (name);
networkOutput.println("read");
int count = in.read();
if (count == 0)
System.out.println("\nMailbox empty.\n");
else
System.out.println("\nMessages:\n");
String message;
for (int i=0; i<count; i++)
{
message = in.readLine();
System.out.println(message);
}
}
} 展开
import java.io.*;
import java.net.*;
import java.util.*;
public class EmailClient
{
private static InetAddress host;
private static final int PORT = 1234;
private static String name;
private static Scanner networkInput, userEntry;
private static PrintWriter networkOutput;
private static BufferedReader in;
public static void main(String[] args) throws IOException
{
try
{
host = InetAddress.getLocalHost();
}
catch(UnknownHostException uhEx)
{
System.out.println("Host ID not found!");
System.exit(1);
}
userEntry = new Scanner(System.in);
do
{
System.out.print("\nEnter name ('Dave' or 'Karen'): ");
name = userEntry.nextLine();
}while (!name.equals("Dave") && !name.equals("Karen"));
talkToServer();
}
private static void talkToServer() throws IOException
{
String option, message, response;
do
{
Socket link = new Socket(host,PORT);
in = new BufferedReader(new InputStreamReader(link.getInputStream()));
networkOutput = new PrintWriter(link.getOutputStream(),true);
do
{
System.out.print("\nEnter option 'send' or 'read':");
option = userEntry.nextLine();
}while (!option.equals("send") && !option.equals("read"));
if (option.equals("send"))
doSend();
else
doRead();
link.close();
System.out.print("\nDo you want to send/read again? (y/n) : ");
option = userEntry.nextLine();
}while (!option.equals("n"));
}
private static void doSend() throws IOException
{
System.out.println("\nEnter 1-line message: ");
String message = userEntry.nextLine();
networkOutput.println(name);
networkOutput.println("send");
networkOutput.println(message);
}
private static void doRead() throws IOException
{
networkOutput.println (name);
networkOutput.println("read");
int count = in.read();
if (count == 0)
System.out.println("\nMailbox empty.\n");
else
System.out.println("\nMessages:\n");
String message;
for (int i=0; i<count; i++)
{
message = in.readLine();
System.out.println(message);
}
}
} 展开
1个回答
2009-01-18
展开全部
java GUI求解 源代码如下,求用GUI修改输入输出介面,看不懂,真的是看不懂,太乱了,乱七八糟
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询