📄 dashboardarea.java
字号:
/*
* Created on Feb 16, 2006
*
* 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.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.*;
import org.GTADS.messenger.MessageAdapter;
import org.GTADS.protocol.MetaData;
import org.GTADS.usermanager.TranslateManager;
import org.GTADS.client.swing.*;
/**
* @author sday
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class DashboardArea extends JPanel implements ActionListener{
private TranslateManager locale = TranslateManager.getInstance();
private JLabel gamesCaption = new JLabel(locale.printLocale("Games") + ": ");
private JLabel numberOfGames = new JLabel();
private JLabel usersCaption = new JLabel(locale.printLocale("User")+ ": ");
private JLabel numberOfUsers = new JLabel();
private GTADSButton joinGameButton = new GTADSButton("Join Game");
private GTADSButton hostGameButton = new GTADSButton("Host Game");
private GTADSButton testProxyButton = new GTADSButton("Test Proxy Port");
public DashboardArea (){
setPanelAttributes();
setComponentsAttributes();
new DashboardRefresher();
}
private void setPanelAttributes(){
this.setLayout(new FlowLayout(FlowLayout.LEFT));
this.setBackground(Color.black);
this.setForeground(Color.white);
}
private void setComponentsAttributes(){
gamesCaption.setForeground(Color.red);
numberOfGames.setForeground(Color.red);
usersCaption.setForeground(Color.red);
numberOfUsers.setForeground(Color.red);
joinGameButton.setToolTipText("Click here to join a game room");
hostGameButton.setToolTipText("Click here to host a game");
joinGameButton.addActionListener(this);
hostGameButton.addActionListener(this);
testProxyButton.addActionListener(this);
this.add(gamesCaption);
this.add(numberOfGames);
this.add(Box.createHorizontalStrut(5));
this.add(usersCaption);
this.add(numberOfUsers);
this.add(Box.createHorizontalStrut(20));
this.add(joinGameButton);
this.add(Box.createHorizontalStrut(5));
this.add(hostGameButton);
//this.add(Box.createHorizontalStrut(5));
//this.add(testProxyButton);
}
public void setNumberOfUsers(String value){
numberOfUsers.setText(value);
}
public void setNumberOfGamerooms(String value){
numberOfGames.setText(value);
}
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent evt) {
if (evt.getSource().equals(hostGameButton)){
GameroomCreationWindow.getInstance().show();
}
else if (evt.getSource().equals(joinGameButton)){
GameroomListWindow.getInstance().show();
}
else if (evt.getSource().equals(testProxyButton)){
try{
MetaData d = new MetaData(DSChatClient.clientUser.getUsername(), MetaData.GENERIC, MetaData.PROXY_CHECK);
MessageAdapter.sendData(null,DSChatClient.ClientSocket,d,"NULL");
} catch (IOException ioe){
}
}
}
public class DashboardRefresher extends Thread {
public DashboardRefresher(){
start();
}
public void run(){
while (true){
try {
MetaData requestUsersHeader = new MetaData(DSChatClient.clientUser.getUsername(),MetaData.DASHBOARD,
MetaData.GET_NUM_USERS);
MetaData requestGamesHeader = new MetaData(DSChatClient.clientUser.getUsername(),MetaData.DASHBOARD,
MetaData.GET_NUM_GAMEROOMS);
MessageAdapter.sendData(null,DSChatClient.ClientSocket,requestUsersHeader,"NULL");
MessageAdapter.sendData(null,DSChatClient.ClientSocket,requestGamesHeader,"NULL");
Thread.sleep(15000);
} catch (IOException ioe){
return;
} catch (InterruptedException ie){
return;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -