⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientloginscreen.java

📁 是一款国外的网络游戏平台的源码*不是类似浩方那种虚拟局域网技术
💻 JAVA
字号:
/*
 * Created on Jun 5, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.GTADS.client;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;

import javax.swing.JFrame;

import org.GTADS.client.preferences.PreferencesDialog;
import org.GTADS.client.preferences.PreferencesManager;
import org.GTADS.usermanager.TranslateManager;
import org.GTADS.client.swing.*;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ClientLoginScreen extends GTADSFrame implements ActionListener {
	Vector listOfServers;
	GTADSLabel statusLabel = new GTADSLabel();
	protected GTADSComboBox serverList = new GTADSComboBox();
	GTADSTextField usernameField = new GTADSTextField(15);
	GTADSPasswordField passwordField = new GTADSPasswordField(15);
	public static GTADSPanel loginPanel = new GTADSPanel();
	private static ClientLoginScreen instance;
	
	public static ClientLoginScreen getInstance() {
		synchronized(ClientLoginScreen.class){
			if (instance == null) {
				instance = new ClientLoginScreen();
			}
		}
		return instance;
	}
	
	public static void clearInstance(){
		synchronized(ClientLoginScreen.class){
			if (instance != null){
				instance.dispose();
				instance.hide();
				instance = null;
			}
		}
	}
	
	public ClientLoginScreen () {
		super(TranslateManager.getInstance().printLocale("GTADS Client Login") + " " + DSChatClient.VERSION_NAME +
				" " + DSChatClient.VERSION_NUMBER);
		listOfServers = new Vector();
		if (!DSChatClient.isApplet) {
			if (!readInServerNames("servers.dat")){
				listOfServers.add("localhost:7000");
			}
		}
		else {
			listOfServers.add("66.65.97.42:7000");
		}
		init();
	}
	
	private void init() {
		// GUI Login Screen Code
		TranslateManager locale = TranslateManager.getInstance();
		GTADSLabel username = new GTADSLabel(locale.printLocale("Username") + ": ");
		GTADSLabel password = new GTADSLabel(locale.printLocale("Password") + ": ");
		GTADSLabel serverListLabel = new GTADSLabel(locale.printLocale("Server") + ": ");
		serverList = new GTADSComboBox(listOfServers);
		GTADSButton okButton = new GTADSButton(locale.printLocale("Ok"));
		GTADSButton newUserButton = new GTADSButton(locale.printLocale("New User"));
		GTADSButton exitButton = new GTADSButton(locale.printLocale("Exit"));
		GTADSButton preferencesButton = new GTADSButton(locale.printLocale("Preferences"));
		
		passwordField.setEchoChar('*');
		
		this.usernameField.setText(PreferencesManager.getInstance().getDefaultUsername());
		if (PreferencesManager.getInstance().getPasswordSaved()){
			this.passwordField.setText(PreferencesManager.getInstance().getDefaultPassword());
		}
		serverList.setEditable(true);
		exitButton.addActionListener(this);
		exitButton.setActionCommand("Exit Program");
		okButton.addActionListener(this);
		okButton.setActionCommand("Ok");
		newUserButton.addActionListener(this);
		newUserButton.setActionCommand("New User");
		preferencesButton.addActionListener(this);
		preferencesButton.setActionCommand("Preferences");
		
	    this.setSize(400,250);
		if (!DSChatClient.isApplet) {
			this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		}

		GridLayout thisLayout = new GridLayout(6,2,2,5);
		loginPanel.setLayout(thisLayout);
		loginPanel.add(username);
		loginPanel.add(usernameField);
		loginPanel.add(password);
		loginPanel.add(passwordField);
		loginPanel.add(serverListLabel);
		loginPanel.add(serverList);
		loginPanel.add(statusLabel);
		loginPanel.add(new GTADSLabel());
		loginPanel.add(okButton);
		loginPanel.add(newUserButton);
		loginPanel.add(exitButton);
		loginPanel.add(preferencesButton);
		
		this.setResizable(false);
		
		setContentPane(loginPanel);
		pack();
		
		this.show();		
	}
	
	public void writeStatusLabel(String text){
		statusLabel.setText(text);
	}
	
	public void actionPerformed(ActionEvent evt) {
		if (evt.getActionCommand().equalsIgnoreCase("Exit Program"))
			if (!DSChatClient.isApplet)
				System.exit(0);
			else {
				hide();
			}
		else if (evt.getActionCommand().equalsIgnoreCase("Ok")){
			writeStatusLabel("Connecting...");
			new ClientConnectionHandler(usernameField.getText(), passwordField.getText(), (String)serverList.getSelectedItem());
		}
		else if (evt.getActionCommand().equalsIgnoreCase("New User")){
			//new ClientConnectionHandler(MetaData.NEW_USER_ACCT, MetaData.NEW_USER_ACCT, (String)serverList.getSelectedItem());
			NewUserDialog.getInstance();
		}
		else if (evt.getActionCommand().equalsIgnoreCase("Preferences")){
			PreferencesDialog.getInstance().show();
		}
	}
	public String getUsername(){
		return usernameField.getText();
	}
	
	private boolean readInServerNames(String filename){
		try {
			FileReader serversFile = new FileReader(filename);
			BufferedReader inputBuffer = new BufferedReader(serversFile);
			String serverLine = new String();
			boolean endOfFile = false;
			Vector listOfServers = new Vector();
			
			while (!endOfFile){
				serverLine = inputBuffer.readLine();
				if (serverLine == null)
					endOfFile = true;
				else {
					listOfServers.add(serverLine);
				}
			}
			serversFile.close();
			this.listOfServers = new Vector(listOfServers);
		} catch (FileNotFoundException fnf) {
			return false;
		}
		catch (IOException eof){
			return false;
		}
		return true;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -