📄 statepanel.java
字号:
package bin;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.SoftBevelBorder;
public class StatePanel extends JPanel
{
private JLabel labPass;
private JLabel labScore;
private JLabel labGameBOy;
private JLabel labOgre;
private static JLabel labPassValue=null;
private static JLabel labScoreValue=new JLabel("0");
private static JLabel labGameBOyValue=null;
private static JLabel labOgreValue=null;
private static int passValue=1;
private static int scoreValue=0;
private static int gameBOyValue=1;
private static int ogreValue=1;
private JLabel labMusic;
private JLabel labStay;
private JLabel labStart;
private JLabel labExit;
private JLabel labMusicCue;
private JLabel labStayCue;
private JLabel labStartCue;
private JLabel labExitCue;
private ImageIcon iconDefault = new ImageIcon("image\\default.jpg");
private ImageIcon iconMusic = new ImageIcon("image\\image1.jpg");
private ImageIcon iconStay = new ImageIcon("image\\image2.jpg");
private ImageIcon iconStart = new ImageIcon("image\\image3.jpg");
private ImageIcon iconExit = new ImageIcon("image\\image4.jpg");
private JLabel exit;
int t;
public StatePanel(final JFrame frame)
{
this.setLayout(null);
this.setOpaque(false);
Border etched = BorderFactory.createEtchedBorder(BevelBorder.LOWERED,Color.BLACK,Color.RED);
Border titled = BorderFactory.createTitledBorder(etched, "状态");
this.setBorder(titled);
labPassValue=new JLabel(StatePanel.passValue+"");
// labScoreValue=new JLabel(StatePanel.scoreValue+"");
labGameBOyValue=new JLabel(StatePanel.gameBOyValue+"");
labOgreValue=new JLabel(StatePanel.ogreValue+"");
addJLabel(30,30,labPass,":关数:",labPassValue);
addJLabel(30,65,labScore,":得分:",labScoreValue);
addJLabel(30,100,labGameBOy,":玩家:",labGameBOyValue);
addJLabel(30,135,labOgre,":怪物:",labOgreValue);
addJLabel(110,170,labMusicCue,"Music");
addJLabel(110,210,labStayCue,"Stay");
addJLabel(110,250,labStartCue,"Start");
addJLabel(110,290,labExitCue,"Exit");
// addJLabel(30,170,labMusic,icon1,icon4);
// addJLabel(30,210,labStay,icon2);
// addJLabel(30,250,labStart,icon3);
// addJLabel(30,290,labExit,icon4);
labMusic=new JLabel(iconDefault);
labStay=new JLabel(iconDefault);
labStart=new JLabel(iconDefault);
labExit=new JLabel(iconDefault);
Border border1 = BorderFactory.createEtchedBorder(BevelBorder.LOWERED,Color.GRAY,Color.GRAY);
SoftBevelBorder border2=new SoftBevelBorder(BevelBorder.LOWERED,Color.WHITE,Color.GRAY);
Border border= BorderFactory.createCompoundBorder(border1,border2);
labMusic.setBorder(border );
labMusic.setBounds(30,170,35,35);
this.add(labMusic);
labStay.setBorder(border );
labStay.setBounds(30,210,35,35);
this.add(labStay);
labStart.setBorder(border );
labStart.setBounds(30,250,35,35);
this.add(labStart);
labExit.setBorder(border );
labExit.setBounds(30,290,35,35);
this.add(labExit);
final JLabel rectangle=new JLabel();
Border bord = BorderFactory.createEtchedBorder(BevelBorder.LOWERED,Color.GRAY,Color.GRAY);
rectangle.setBorder(bord );
rectangle.setBounds(27,167,41,41);
this.add(rectangle);
labMusic.addMouseListener(new
MouseAdapter(){
public void mouseClicked(MouseEvent e) {
MapPanel.play.muiscPlay();
}
public void mouseEntered(MouseEvent e) {
labMusic.setIcon(iconMusic);
Play.buttonClipStats();
rectangle.setBounds(27,167,41,41);
}
public void mouseExited(MouseEvent e) {
Play.buttonClipStats();
labMusic.setIcon(iconDefault);
}
});
labStay.addMouseListener(new
MouseAdapter(){
public void mouseClicked(MouseEvent e) {
MapPanel.play.muiscStop();
}
public void mouseEntered(MouseEvent e) {
labStay.setIcon(iconStay);
Play.buttonClipStats();
rectangle.setBounds(27,207,41,41);
}
public void mouseExited(MouseEvent e) {
Play.buttonClipStats();
labStay.setIcon(iconDefault);
}
});
labStart.addMouseListener(new
MouseAdapter(){
public void mouseClicked(MouseEvent e) {
MapPanel.play.muiscPlay();
}
public void mouseEntered(MouseEvent e) {
labStart.setIcon(iconStart);
Play.buttonClipStats();
rectangle.setBounds(27,247,41,41);
}
public void mouseExited(MouseEvent e) {
Play.buttonClipStats();
labStart.setIcon(iconDefault);
}
});
labExit.addMouseListener(new
MouseAdapter(){
public void mouseClicked(MouseEvent e) {
frame.setVisible(false);
MapPanel.setLabState(true);
}
public void mouseEntered(MouseEvent e) {
labExit.setIcon(iconExit);
Play.buttonClipStats();
rectangle.setBounds(27,287,41,41);
}
public void mouseExited(MouseEvent e) {
Play.buttonClipStats();
labExit.setIcon(iconDefault);
}
});
/* try
{
img = ImageIO.read(new File("mp3.gif"));//.getImage( ); System.out.println(0);
}
catch(IOException exception)
{
System.out.println("11111111111");
exception.printStackTrace();
}
Icon icon=new ImageIcon(img);
JLabel labIcon=new JLabel(icon1);
labIcon.setBounds(10,40,60,60);
this.add(labIcon);
*/
}
public static int getPassValue()
{
return passValue;
}
public static int getScoreValue()
{
return scoreValue;
}
public static int getGameBOyValue()
{
return gameBOyValue;
}
public static int getOgreValue()
{
return ogreValue;
}
public void addJLabel(int x,int y,JLabel label,String text)
{
label=new JLabel(text);
label.setForeground(Color.GRAY);
label.setFont(new Font(null,Font.PLAIN,10));
label.setBounds(x,y,50,25);
this.add(label);
}
public void addJLabel(int x,int y,JLabel label,String text,JLabel label1)
{
label=new JLabel(text);
label.setForeground(Color.GREEN);
label.setFont(new Font(null,Font.BOLD,12));
label1.setForeground(Color.BLACK);
label1.setFont(new Font(null,Font.PLAIN,10));
final JPanel panel=new JPanel();
panel.setLayout(null);
label.setBounds(15,3,50,25);
label1.setBounds(80,3,50,25);
panel.setOpaque(false);
panel.add(label);
panel.add(label1);
Border borderName1 = BorderFactory.createEtchedBorder(BevelBorder.LOWERED,Color.GREEN,Color.CYAN);
SoftBevelBorder borderName2=new SoftBevelBorder(BevelBorder.LOWERED,Color.WHITE,Color.GRAY);
final Border border= BorderFactory.createCompoundBorder(borderName1,borderName2);
panel.setBorder(border);
panel.setBounds(x,y,150,25);
this.add(panel);
final Border etchedRed = BorderFactory.createEtchedBorder(BevelBorder.LOWERED,Color.BLACK,Color.RED);
panel.addMouseListener(new
MouseListener(){
public void mouseClicked(MouseEvent e) {
Play.frameMove();
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
panel.setBorder(etchedRed);
}
public void mouseExited(MouseEvent e) {
panel.setBorder(border);
}
});
}
public static void setLabScoreValue()
{
scoreValue= Gameboy.goal;
// System.out.println(scoreValue+"");
labScoreValue.setText(scoreValue+"");
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -