📄 userlist_screen.java
字号:
/**
* Importing the basic packages required by various classes during
* the execution of the program.
*/
import com.sun.kjava.*;
import java.lang.*;
import javax.microedition.io.*;
import java.io.*;
import java.util.*;
/**
* The packages below are included because these packages are
* required by the XML classes.
*/
import org.kxml.*;
import org.kxml.io.*;
import org.kxml.parser.*;
// Declaration of a class userlist_screen..
public class userlist_screen extends Spotlet
{
// Declaring button variables.
private Button refresh;
private Button search;
private Button viewfiles;
private Button browse_user;
private Button exit;
// Declaring ScrollTextBox and textField variables.
private ScrollTextBox userlist;
private TextField option;
Vector ip_address;
// Declaring StreamConnection variable used for Sockets..
StreamConnection socket = null;
// Declaring InputStreams and OutputStreams used by the socket
// connections.
InputStream socket_inputstream;
OutputStream socket_outputstream;
/**
* Declaraing variables for the xmlparser and parse event(Where
* the call backs after the parsing will be stored.
*/
AbstractXmlParser xmlparser;
ParseEvent event;
/**
* Declaraing variables for storing the parameters passed on to
* the class.
*/
Vector folder_vector;
Vector users_connected;
String text_for_display;
/**
* Declaraing variables to folder_data where the folder information
* is stored similerly the variable file_data where the file
* information is stored.
*/
String folder_data;
String file_data;
int counter;
String address;
String user_data;
Vector record_of_users;
// Constructor of the class userlist_screen is called..
userlist_screen(String text, Vector ip_addresses,Vector users_connected, boolean viewfile_flag ,Vector record_of_users)
{
// The current graphics is obtained...
Graphics graphics = Graphics.getGraphics();
/**
* Initializing the variable of the graphics class and clearing
* the drawing region by calling the appropriate functions of
* the Graphics class namely (resetDrawRegion() and clearScreen()).
*/
graphics.resetDrawRegion();
graphics.clearScreen();
/**
* Displaying a string (Title) at a specified position by using
* the member function of the Graphics class
*/
graphics.drawString("List of Users",50,5);
// The variables are initialized by the parameters earlier defined
ip_address = ip_addresses;
user_data = text;
this.users_connected = users_connected;
this.record_of_users = record_of_users;
// To make the spotlet as the current spotlet..
register(NO_EVENT_OPTIONS);
/**
* Initializing the button object "refresh", placing it on the screen
* at the appropriate position and then painting(drawing it).
*/
refresh = new Button("Refresh",10,20);
refresh.paint();
/**
* Initializing the button object "search", placing it on the screen
* at the appropriate position and then painting(drawing it).
*/
search = new Button("Search",60,20);
search.paint();
/**
* Initializing the button object "viewfiles", placing it on the screen
* at the appropriate position, the painting of the "viewfiles" button
* will be decided by checking the view_file flag if the flag is true
* then the button will be painted on the screen else not.
*/
viewfiles = new Button("View Files",110,20);
if (viewfile_flag)
{
viewfiles.paint();
}
/**
* Initializing the ScrollTextBox object userlist, placing it on
* the screen at the appropriate position and then painting(drawing it).
*/
userlist = new ScrollTextBox(text,10,40,130,100);
userlist.paint();
/**
* Initializing the TextFiled object option, placing it on the screen
* at the appropriate position ,painting(drawing it) and making the
* caret blink by setting the TextField as the current field.
*/
option = new TextField("User No.:",10,145,50,10);
option.paint();
option.setUpperCase(true);
option.setFocus();
/**
* Initializing the button object browse_user, placing it on
* the screen at the appropriate position and then painting(drawing it).
*/
browse_user = new Button("Browse",70,145);
browse_user.paint();
/**
* Initializing the button object exit, placing it on the screen
* at the appropriate position and then painting(drawing it).
*/
exit = new Button("Exit",120,145);
exit.paint();
} // end of the constructor userlist_screen
// Event Handling function. (KeyDown)..
public void keyDown(int x)
{
// Handle the input if the TextField is in focus.
if(option.hasFocus())
{
option.handleKeyDown(x);
}
} // End KeyDowm
// Event Handling function. (penDown)..
public void penDown(int x, int y)
{
// If refresh Button is pressed..
if(refresh.pressed(x,y))
{
// Remove the focus from the TextField and kill the TextField
// blinking caret.
option.loseFocus();
option.killCaret();
// To show a new class fist unregister all the controls of the
// existing class
unregister();
// Create an object of the class peer_application and call the
// function startReading() to send a request to the server
peer_application refresh_application = new peer_application();
refresh_application.startReading();
// Then call the parser function it will return a vector.
Vector ip_addresses = refresh_application.parseData();
String text_for_display = refresh_application.returnTextForDisplay();
Vector users_connected = refresh_application.returnUsersConnected();
// Call the class userlist_screen with the parameters obtained in the
// previous lines..
new userlist_screen(text_for_display,ip_addresses,users_connected,false,null);
}
// If search(Server Search) Button is pressed
if(search.pressed(x,y))
{
// Remove the focus from the TextField and kill the TextField
// blinking caret.
option.loseFocus();
option.killCaret();
// To show a new class fist unregister all the controls of the
// existing class
unregister();
// Call the class serversearch with the parameters.
new serversearch(user_data,ip_address,users_connected);
}
// If viewfiles is pressed..
if(viewfiles.pressed(x,y))
{
// The option enetered by the user in the TextField is obtained.
String user_number = option.getText();
try
{
//Converting it to an integer value.
int userID = Integer.parseInt(user_number);
try
{
// The variables are assigned ..
String textDisplay = "";
String folderText="";
String fileText="";
// From the vector ip_address the address is obtained of the
// user whose serial number is entered.
address = (String)ip_address.elementAt(userID-1);
// From another vector record_of_users an enumeration is
// initialized.
Enumeration enum = record_of_users.elements();
// A while loop is used which matches the ip_address with the
// enumeration
while (enum.hasMoreElements())
{
if (((String)enum.nextElement()).equals(address))
{
String temp = (String)enum.nextElement();
// If a match is found then the flahg for file / folder is
// checked and accordingly the Files/ folders are placed in
// their respective position.
if (((String)enum.nextElement()).equals("1"))
{
fileText = fileText+temp+"\n";
}
else
{
folderText = folderText+temp+"\n";
}
}
}
// A string variable is used to display the text in the ScrollTextBox
textDisplay = " Folders \n"+folderText+"\n"+" Files \n"+fileText;
// Remove the focus from the TextField and kill the TextField
// blinking caret.
option.loseFocus();
option.killCaret();
// To show a new class fist unregister all the controls of the
// existing class.
unregister();
// Call to the class show files...
new showfiles(textDisplay,null, null, "ROOT",true);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -