📄 statsdialog.java
字号:
// Yura Mamyrin
package risk.ui.FlashGUI;
import risk.engine.guishared.*;
import risk.engine.*;
import risk.engine.core.RiskGame;
import javax.swing.JDialog;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.awt.Graphics;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Frame;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JSlider;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import java.awt.font.TextLayout;
import java.awt.font.FontRenderContext;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.RenderingHints;
import java.awt.Polygon;
import java.awt.geom.Ellipse2D;
import javax.swing.ImageIcon;
/**
* <p> Move Dialog for FlashGUI </p>
* @author Yura Mamyrin
*/
public class StatsDialog extends JDialog implements ActionListener {
private BufferedImage Back;
private Risk myrisk;
private StatsPanel graph;
private java.util.ResourceBundle resb;
public StatsDialog(Frame parent, boolean modal, Risk r) {
super(parent, modal);
myrisk = r;
try {
Back = ImageIO.read( this.getClass().getResource("graph.jpg") );
}
catch (Exception e) { }
initGUI();
setResizable(false);
pack();
}
/** This method is called from within the constructor to initialize the form. */
/**
* Initialises the GUI
*/
private void initGUI()
{
resb = risk.engine.translation.TranslationBundle.getBundle();
setTitle( resb.getString("swing.tab.statistics") );
graphPanel thisgraph = new graphPanel();
Dimension d = new Dimension(740, 600);
thisgraph.setPreferredSize(d);
thisgraph.setMinimumSize(d);
thisgraph.setMaximumSize(d);
thisgraph.setLayout(null);
JButton statbutton;
int x=49;
int y=483;
int w=107;
int h=33;
int s=1;
thisgraph.addButton("countries",x,y,w,h,s);
x=x+w;
s++;
thisgraph.addButton("armies",x,y,w,h,s);
x=x+w;
s++;
thisgraph.addButton("kills",x,y,w,h,s);
x=x+w;
s++;
thisgraph.addButton("casualties",x,y,w,h,s);
x=x+w;
s++;
thisgraph.addButton("reinforcements",x,y,w,h,s);
x=x+w;
s++;
thisgraph.addButton("continents",x,y,w,h,s);
x=49;
y=y+h;
s++;
thisgraph.addButton("empire",x,y,w,h,s);
x=x+w;
s++;
thisgraph.addButton("attacks",x,y,w,h,s);
x=x+w;
s++;
thisgraph.addButton("retreats",x,y,w,h,s);
x=x+w;
s++;
thisgraph.addButton("victories",x,y,w,h,s);
x=x+w;
s++;
thisgraph.addButton("defeats",x,y,w,h,s);
x=x+w;
s++;
thisgraph.addButton("attacked",x,y,w,h,s);
graph = new StatsPanel(myrisk);
graph.setBounds(50,50,640,400);
thisgraph.add(graph);
getContentPane().add(thisgraph);
addWindowListener(
new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm();
}
}
);
}
public void actionPerformed(ActionEvent a) {
graph.repaintStats( Integer.parseInt( a.getActionCommand() ) );
graph.repaint();
}
/** Exit the Application */
/**
* Closes the GUI
*/
private void exitForm() {
((GameFrame)getParent()).displayGraph();
}
class graphPanel extends JPanel {
/**
* Paints the graphic
* @param g Graphics
*/
public void paintComponent(Graphics g) {
g.drawImage(Back.getSubimage(0, 0, 50, 400), 0, 50, this);
g.drawImage(Back.getSubimage(50, 0, 50, 400), 690, 50, this);
g.drawImage(Back.getSubimage(100, 0, 740, 50), 0, 0, this);
g.drawImage(Back.getSubimage(100, 182, 740, 150), 0, 450, this);
}
public void addButton(String a, int x,int y,int w,int h,int s) {
JButton statbutton = new JButton(resb.getString("swing.toolbar."+a));
statbutton.setActionCommand(s+"");
statbutton.addActionListener( StatsDialog.this );
statbutton.setBounds(x, y, w , h );
NewGameFrame.sortOutButton( statbutton, Back.getSubimage(x+100,y-433+165,w,h), Back.getSubimage(x+100,y-433,w,h), Back.getSubimage(x+100,y-433+66,w,h) );
add(statbutton);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -