📄 swingguipanel.java
字号:
if (pointer > history.size()-2 ) {
Toolkit.getDefaultToolkit().beep();
}
else if (pointer == history.size()-2 ) {
Command.setText(temptext);
pointer++;
}
else {
pointer=pointer+2;
Command.setText( (String)history.elementAt(pointer) );
pointer--;
}
}
else {
pointer = history.size()-1;
}
}
});
setOpaque(false);
statusBar.setText(resbundle.getString( "swing.status.ready"));
}
private void cgo(String input) {
if (input.equals("exit") ) {
// Testing.append("Exit.\n");
System.exit(0);
}
else if (input.equals("help") ) {
Commands();
}
else if (input.equals("about") ) {
openAbout();
}
else if (input.equals("clear") ) {
// Testing.append("Console cleared\n");
Console.setText("");
}
else if (input.equals("manual") ) {
try {
RiskUtil.openDocs( resbundle.getString("helpfiles.swing") );
}
catch(Exception e) {
addOutput("Unable to open manual: "+e.getMessage() );
}
}
else {
go(input);
}
}
public void addOutput(String output) {
Console.append(output + System.getProperty("line.separator") );
Console.setCaretPosition(Console.getDocument().getLength());
}
public void blockInput() {
statusBar.setText(resbundle.getString("swing.status.working"));
Submit.setEnabled(false);
Command.setEnabled(false);
}
public void getInput() {
Submit.setEnabled(true);
Command.setEnabled(true);
Command.requestFocus();
statusBar.setText(resbundle.getString("swing.status.doneready"));
}
public void setVisible(boolean v) {
super.setVisible(v);
Command.requestFocus(); // does not work too well
}
public JToolBar getToolBar() {
return toolbarCon;
}
public JMenu getMenu() {
return cConsole;
}
public void actionPerformed(ActionEvent a) {
if (a.getActionCommand().equals("read command")) {
String input = Command.getText();
Command.setText("");
history.add(input);
pointer = history.size()-1;
cgo(input);
}
else if (a.getActionCommand().equals("run script")) {
JFileChooser fc = new JFileChooser();
RiskFileFilter filter = new RiskFileFilter(RiskFileFilter.RISK_SCRIPT_FILES);
fc.setFileFilter(filter);
int returnVal = fc.showOpenDialog( RiskUtil.findParentFrame(this) );
if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION) {
java.io.File file = fc.getSelectedFile();
// Write your code here what to do with selected file
try {
// Testing.append("Opening file: "+ file.getPath() +"\n");
// Testing.append("Running Script...\n");
FileReader filein = new FileReader(file);
BufferedReader bufferin = new BufferedReader(filein);
String input = bufferin.readLine();
while(input != null) {
go(input);
input = bufferin.readLine();
}
bufferin.close();
// Testing.append("Script end\n");
}
catch(Exception error) {
// Testing.append("Error: "+error.getMessage() + "\n");
}
} else {
// Write your code here what to do if user has canceled Open dialog
}
}
else if (a.getActionCommand().equals("save console")) {
saveLog(Console);
}
else if (a.getActionCommand().equals("clear console")) {
Console.setText("");
}
else if (a.getActionCommand().equals("clear history")) {
history.clear();
pointer = -1;
}
else {
SwingGUIPanel.this.actionPerformed(a);
}
}
}
class GameTab extends JPanel implements SwingGUITab, ActionListener {
private JPanel Pix;
private JPanel guiGame;
private JLabel gameStatus;
private JMenu gGame;
private JToolBar toolbarGUI;
private boolean serverOn;
private JButton gNewGame;
private JButton gLoadGame;
private JButton gSaveGame;
private JButton gCloseGame;
private JButton gJoinGame;
private JButton gStartServer;
private JButton gOptions;
private JMenuItem gmOptions;
private JMenuItem gmReplay;
private JMenuItem gmStartServer;
private JMenuItem gmJoinGame;
private JMenuItem gmNewGame;
private JMenuItem gmLoadGame;
private JMenuItem gmSaveGame;
private JMenuItem gmCloseGame;
public JMenu getMenu() {
return gGame;
}
public JToolBar getToolBar() {
return toolbarGUI;
}
public GameTab() {
setName( resbundle.getString("swing.tab.game") );
serverOn=false;
// ################### GUI #######################
gameStatus = new JLabel("");
Pix = new JPanel( new BorderLayout() );
Pix.setOpaque(false);
lobby = new JButton( resbundle.getString("lobby.run") );
lobby.setActionCommand("lobby");
lobby.addActionListener( this );
lobby.setBackground( Color.RED );
lobby.setVisible(false);
// cant use this as it goes even worse in xp
//lobby.setContentAreaFilled(false);
JLabel pixlogo = new JLabel("yura.net "+product+", "+RiskUtil.getGameName()+" IDE", new javax.swing.ImageIcon( this.getClass().getResource("about.jpg") ) , JLabel.CENTER );
pixlogo.setHorizontalTextPosition( JLabel.CENTER );
pixlogo.setVerticalTextPosition( JLabel.TOP );
Pix.add( lobby , BorderLayout.NORTH );
Pix.add( pixlogo );
setLayout(new java.awt.BorderLayout());
add(Pix, java.awt.BorderLayout.CENTER );
add(gameStatus, java.awt.BorderLayout.SOUTH);
javax.swing.border.Border goodBorder = BorderFactory.createLoweredBevelBorder(); // Con.getBorder();
gameStatus.setBorder( goodBorder );
mapPic = new JLabel();
mapPic.setBorder( goodBorder );
Dimension size = new Dimension(203,127);
mapPic.setPreferredSize(size);
mapPic.setMinimumSize(size);
mapPic.setMaximumSize(size);
Insets margin = new Insets(2,2,2,2);
showMission = new JButton(resbundle.getString("swing.button.mission"));
showMission.setToolTipText(resbundle.getString("game.button.mission"));
showMission.addActionListener( this );
showMission.setActionCommand("showmission");
showMission.setMargin(margin);
showCards = new JButton(resbundle.getString("swing.button.cards"));
showCards.setToolTipText(resbundle.getString("game.button.cards"));
showCards.addActionListener( this );
showCards.setActionCommand("showcards");
showCards.setMargin(margin);
Undo = new JButton(resbundle.getString("swing.button.undo"));
Undo.setToolTipText(resbundle.getString("game.button.undo"));
Undo.addActionListener( this );
Undo.setActionCommand("undo");
Undo.setMargin(margin);
JButton viewContinents = new JButton(resbundle.getString("swing.button.continents"));
viewContinents.addActionListener( this );
viewContinents.setActionCommand("continents");
viewContinents.setMargin(margin);
moveNumber = new JSlider();
slider = new JSlider();
armies = new JLabel();
toolbarGUI = new JToolBar();
toolbarGUI.setRollover(true);
autoplace = new JButton(resbundle.getString("game.button.go.autoplace"));
Dimension gameOptionsSize = new Dimension(PicturePanel.PP_X,25);
gameOptions = makeGameOptionsPanel();
gameOptions.setPreferredSize(gameOptionsSize);
gameOptions.setMinimumSize(gameOptionsSize);
gameOptions.setMaximumSize(gameOptionsSize);
gameOptions.add(viewContinents);
guiSetup = new SetupPanel();
guiGame = new GamePanel();
guiSetup.setOpaque(false);
guiGame.setOpaque(false);
// make toolbar
gNewGame = new JButton(resbundle.getString("swing.menu.new"));
gLoadGame = new JButton(resbundle.getString("swing.menu.load"));
gSaveGame = new JButton(resbundle.getString("swing.menu.save"));
gCloseGame = new JButton(resbundle.getString("swing.menu.close"));
gOptions = new JButton(resbundle.getString("swing.menu.options"));
gJoinGame = new JButton(resbundle.getString("swing.menu.joingame"));
gStartServer = new JButton(resbundle.getString("swing.menu.startserver"));
JButton gManual = new JButton(resbundle.getString("swing.menu.manual"));
JButton gAbout = new JButton(resbundle.getString("swing.menu.about"));
JButton gQuit = new JButton(resbundle.getString("swing.menu.quit"));
gNewGame.setActionCommand("new game");
gNewGame.addActionListener( this );
gLoadGame.setActionCommand("load game");
gLoadGame.addActionListener( this );
gSaveGame.setActionCommand("save game");
gSaveGame.addActionListener( this );
gCloseGame.setActionCommand("close game");
gCloseGame.addActionListener( this );
gOptions.setActionCommand("options");
gOptions.addActionListener( this );
gManual.setActionCommand("manual");
gManual.addActionListener( this );
gAbout.setActionCommand("about");
gAbout.addActionListener( this );
gQuit.setActionCommand("quit");
gQuit.addActionListener( this );
gStartServer.setActionCommand("start server");
gStartServer.addActionListener( this );
gJoinGame.setActionCommand("join game");
gJoinGame.addActionListener( this );
toolbarGUI.add(gNewGame);
toolbarGUI.add(gLoadGame);
toolbarGUI.add(gSaveGame);
toolbarGUI.add(gCloseGame);
toolbarGUI.addSeparator();
toolbarGUI.add(gJoinGame);
toolbarGUI.add(gStartServer);
toolbarGUI.addSeparator();
toolbarGUI.add(gOptions);
toolbarGUI.add(gManual);
toolbarGUI.add(gAbout);
if (RiskUtil.checkForNoSandbox()) { toolbarGUI.add(gQuit); }
toolbarGUI.setFloatable(false);
// create Game menu item
gGame = new JMenu(resbundle.getString("swing.menu.game"));
gGame.setMnemonic('G');
gmNewGame = new JMenuItem(resbundle.getString("swing.menu.new"));
gmNewGame.setMnemonic('N');
gmNewGame.setActionCommand("new game");
gmNewGame.addActionListener( this );
gGame.add(gmNewGame);
gmLoadGame = new JMenuItem(resbundle.getString("swing.menu.load"));
gmLoadGame.setMnemonic('L');
gmLoadGame.setActionCommand("load game");
gmLoadGame.addActionListener( this );
gGame.add(gmLoadGame);
gmSaveGame = new JMenuItem(resbundle.getString("swing.menu.save"));
gmSaveGame.setMnemonic('S');
gmSaveGame.setActionCommand("save game");
gmSaveGame.addActionListener( this );
gGame.add(gmSaveGame);
gmCloseGame = new JMenuItem(resbundle.getString("swing.menu.close"));
gmCloseGame.setMnemonic('C');
gmCloseGame.setActionCommand("close game");
gmCloseGame.addActionListener( this );
gGame.add(gmCloseGame);
gGame.addSeparator();
gmJoinGame = new JMenuItem(resbundle.getString("swing.menu.joingame"));
gmJoinGame.setMnemonic('J');
gmJoinGame.setActionCommand("join game");
gmJoinGame.addActionListener( this );
gGame.add(gmJoinGame);
gmStartServer = new JMenuItem(resbundle.getString("swing.menu.startserver"));
gmStartServer.setMnemonic('V');
gmStartServer.setActionCommand("start server");
gmStartServer.addActionListener( this );
gGame.add(gmStartServer);
gGame.addSeparator();
gmOptions = new JMenuItem(resbundle.getString("swing.menu.options"));
gmOptions.setMnemonic('O');
gmOptions.setActionCommand("options");
gmOptions.addActionListener( this );
gGame.add(gmOptions);
gmReplay = new JMenuItem("Replay");
gmReplay.setMnemonic('R');
gmReplay.setActionCommand("replay");
gmReplay.addActionListener( this );
gGame.add(gmReplay);
if (RiskUtil.checkForNoSandbox()) {
gGame.addSeparator();
JMenuItem gmQuit = new JMenuItem(resbundle.getString("swing.menu.quit"));
gmQuit.setMnemonic('Q');
gmQuit.setActionCommand("quit");
gmQuit.addActionListener( this );
gGame.add(gmQuit);
}
roll1 = new JButton(resbundle.getString("swing.dice.roll1"));
roll2 = new JButton(resbundle.getString("swing.dice.roll2"));
roll3 = new JButton(resbundle.getString("swing.dice.roll3"));
roll1.setActionCommand("roll 1");
roll2.setActionCommand("roll 2");
roll3.setActionCommand("roll 3");
roll1.addActionListener(this);
roll2.addActionListener(this);
roll3.addActionListener(this);
gOptions.setEnabled(false);
gmOptions.setEnabled(false);
gmReplay.setEnabled(false);
gSaveGame.setEnabled(false);
gCloseGame.setEnabled(false);
gmSaveGame.setEnabled(false);
gmCloseGame.setEnabled(false);
setOpaque(false);
}
public void actionPerformed(ActionEvent a) {
if (a.getActionCommand().equals("showmission")) {
showMission( myrisk.getCurrentMission() );
}
else if (a.getActionCommand().equals("showcards")) {
openCards();
}
else if (a.getActionCommand().equals("undo")) {
go("undo");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -