📄 loginscence.java
字号:
package pp.scence;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.net.*;
import like.graphics.*;
import like.scence2D.*;
public class LoginScence extends Scence
implements ActionListener, MouseListener
{
String loginMsg;
Image offscreen;
Image backGround;
AudioClip login,enter;
TextField player1Name,player2Name;
TextField password1,password2;
ImageIcon confirm_0,confirm_1,exit_0,exit_1;
JButton confirm,exit,about;
public LoginScence(ScenceManger sm)
{
super(sm);
this.setSize(800,600);
this.setUndecorated(true);
this.setVisible(true);//这个不早点写,getGraphics()==null,
GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
this.setLocation((device.getDisplayMode().getWidth()-this.getWidth())/2,
(device.getDisplayMode().getHeight()-this.getHeight())/2);
}
public void init()
{
this.zhenTime = 10000;
ImageLoader loader = new ImageLoader(this,"res\\common\\button.gif",true);
confirm_0 = new ImageIcon(loader.extractCell(0,0,108,37));
confirm_1 = new ImageIcon(loader.extractCell(0,37,108,37));
exit_0 = new ImageIcon(loader.extractCell(0,74,108,37));
exit_1 = new ImageIcon(loader.extractCell(0,111,108,37));
//GUI
this.setLayout(null);
confirm = new JButton(confirm_1);
this.add(confirm);
confirm.setBounds(346,552,108,37);
confirm.addMouseListener(this);
confirm.addActionListener(this);
exit = new JButton(exit_1);
exit.addMouseListener(this);
this.add(exit);
exit.setBounds(456,552,108,37);
exit.addMouseListener(this);
exit.addActionListener(this);
about = new JButton(new ImageIcon("res\\common\\about.gif"));
about.addMouseListener(this);
this.add(about);
about.setBounds(236,552,108,37);
about.addMouseListener(this);
about.addActionListener(this);
String str;
str = (String)htPros.get("name1");
player1Name = new TextField(str);
this.add(player1Name);
player1Name.setBounds(280,468,94,22);
player1Name.addActionListener(this);
str = (String)htPros.get("name2");
player2Name = new TextField(str);
this.add(player2Name);
player2Name.setBounds(459,468,94,22);
player2Name.addActionListener(this);
player1Name.setText("如果天有晴");
player2Name.setText("★★晴天");
password1 = new TextField();
this.add(password1);
password1.setBounds(280,493,94,22);
password1.setText("暂时不用密码");
password1.setEditable(false);
password2 = new TextField();
this.add(password2);
password2.setBounds(459,493,94,22);
password2.setText("暂时不用密码");
password2.setEditable(false);
//其他
loginMsg = (String)htPros.get("login");
try
{
enter = Applet.newAudioClip(new URL("file","localhost","res\\au\\common\\enter.au"));
login = Applet.newAudioClip(new URL("file","localhost","res\\au\\common\\login.au"));
this.htPros.put("enter",enter);
}
catch(Exception e){}
this.fullWidth = 800;
this.fullHeight = 600;
loader = new ImageLoader(this,"res\\common\\login.gif",true);
this.backGround = loader.getImage();
offscreen = this.createImage(800,600);
super.init();
}
public void start()
{
this.repaint = null;
//super.start();
if(login!=null) login.loop();
}
public void stop()
{
super.stop();
this.login.stop();
this.login = null;
}
public void over()
{
super.over();
this.setVisible(false);
this.toWindow();
this.dispose();
System.exit(0);
}
public void toPlayingScence()
{
this.htPros.put("exit_0",this.exit_0);
this.htPros.put("confirm_0",this.confirm_0);
this.htPros.put("exit_1",this.exit_1);
this.htPros.put("confirm_1",this.confirm_1);
this.htPros.put("name1",this.player1Name.getText());
this.htPros.put("name2",this.player2Name.getText());
File file = MapChooseDialog.showMapChooseDialog(this);
if(file==null || file.isDirectory()) return;
this.htPros.put("mapFile",file.getAbsolutePath());
MessageDialog.showMessageDialog(this,"操作指南",
"玩家一操作:上(R)下(F)左(D)右(G) 放泡泡(A)\n"+
"玩家二操作:上(↑)下(↓)左(←)右(→) 放泡泡(/)\n"+
"退出(ESC) 全屏和窗口切换(F8)\n\n"+
"通过地图编辑器可以制作自己的地图,把做好的\n"+
"地图放到maps文件夹下系统就会自己找到地图了");
super.over();
sm.changeScence(new PlayingScence(sm));
if(!ifFullScreen) this.dispose();
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
if(this.offscreen==null) return;
Graphics og = this.offscreen.getGraphics();
if(og==null)
{
return;
}
og.drawImage(this.backGround,0,0,this);
confirm.repaint();
exit.repaint();
about.repaint();
/*og.setColor(Color.white);
og.setFont(new Font(null,Font.BOLD,35));
og.drawString(loginMsg,35,35);*/
g.drawImage(offscreen,0,0,this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(exit))
{
this.over();
}
else if(e.getSource().equals(about))
{
MessageDialog.showMessageDialog(this,"欢迎使用梦幻泡泡1.0版(厦门大学软件学院)",
"这是我和宿舍好友铠哥心血来潮之作,也是\n"
+"我们的游戏处女作。\n"
+"该作品为模仿盛大泡泡堂游戏,经过内部8个\n"
+"版本的测试,大体上接近官方单机版本了。\n"
+"所有的图片都来自bnb.sdo.com,仅供学习参考\n"
+",请勿用于商业用途。\n"
+"组员分工:\n"
+" 李文耀:负责游戏主体部分,\n"
+" 包括引擎设计,接口设计\n"
+" 和绝大部分的音效处理\n"
+" 林铠 :负责地图编辑器部分,包括绝大部分的\n"
+" 图片处理.\n"
+"开发平台:\n"
+"jdk1.5+JCreator,还有一些图片音乐的处理软件\n\n"
+"版本还在不断更新中哦,最新版本请到\n"
+"https://gro.clinux.org/projects/mhpp/下载\n\n"
+"Allrights open,唯一的要求就是当您更改了软件\n"
+"并打算重新发布的时候请附上您的源代码\n"
+" 厦大软件学院,梦幻泡泡开发小组:)\n"
+" 06.12.14");
}
else
{
this.toPlayingScence();
}
}
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_F8)
{
if(this.ifFullScreen)
this.toWindow();
else
this.toFullScreen();
}
}
/**
* Method mouseClicked
*
*
* @param e
*
*/
public void mouseClicked(MouseEvent e) {
// TODO: 在这添加你的代码
}
/**
* Method mousePressed
*
*
* @param e
*
*/
public void mousePressed(MouseEvent e) {
// TODO: 在这添加你的代码
}
/**
* Method mouseReleased
*
*
* @param e
*
*/
public void mouseReleased(MouseEvent e) {
// TODO: 在这添加你的代码
}
/**
* Method mouseEntered
*
*
* @param e
*
*/
public void mouseEntered(MouseEvent e)
{
if(enter!=null)
enter.play();
/*if((JButton)e.getSource()==this.confirm)
{
this.confirm.setIcon(this.confirm_1);
}
else if((JButton)e.getSource()==this.exit)
{
this.exit.setIcon(exit_1);
}*/
}
/**
* Method mouseExited
*
*
* @param e
*
*/
public void mouseExited(MouseEvent e)
{
/*if((JButton)e.getSource()==this.confirm)
{
this.confirm.setIcon(this.confirm_0);
}
else if((JButton)e.getSource()==this.exit)
{
this.exit.setIcon(exit_0);
}*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -