```java
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
public class LoginJFrame extends JFrame implements MouseListener {
static ArrayList<User>allUsers=new ArrayList<>();
static {
allUsers.add((new User("人生我靠演戏","208937032.7")));
allUsers.add(new User("宇智波佐助","123456"));
}
//登录组件
JButton login=new JButton();
//注册组件
JButton sign=new JButton();
//用户名组件
JTextField username=new JTextField();
//密码组件
JPasswordField password=new JPasswordField();
//验证码组件
JTextField code=new JTextField();
//正确的验证码
JLabel rightCode=new JLabel();
public LoginJFrame(){
//初始化界面
initJFrame();
//初始化组件等
initView();
//展示界面
setVisible(true);
}
public void initJFrame(){
//设置窗体大小
this.setSize(633,423);
//设置标题
this.setTitle("斗地主游戏 v1.0登录");
//设置关闭模式
this.setDefaultCloseOperation(3);
//居中
this.setLocationRelativeTo(null);
//置顶
this.setAlwaysOnTop(true);
//取消默认布局
this.setLayout(null);
}
public void initView(){
// 140, 55, 55, 22
//设置文字模式 样式 长度(文字对象)
Font usernameFont=new Font(null,1,16);
//设置文字组件
JLabel usernameFontTest=new JLabel("用户名");
//设置文字颜色
usernameFontTest.setForeground(Color.black);
//为组件设置文字模式
usernameFontTest.setFont(usernameFont);
//设置组件长度
usernameFontTest.setBounds(140,55,55,22);
//获取面版并把组件塞进去
this.getContentPane().add(usernameFontTest);
//2.添加用户名输入框
// 223, 46, 200, 30
username.setBounds(223,46,200,30);
this.getContentPane().add(username);
// 197, 95, 40, 22
//设置文字模式 样式 长度(文字对象)
Font passwordFont=new Font(null,1,16);
//设置密码组件接受文字对象
JLabel passwordTest=new JLabel("密码");
//设置组件文字颜色
passwordTest.setForeground(Color.black);
//给组件文字添加文字模式
passwordTest.setFont(passwordFont);
//设置组件长度
passwordTest.setBounds(197,95,40,22);
//获取面版把密码文字组件塞进去
this.getContentPane().add(passwordTest);
// 263, 87, 160, 30
//3.添加密码输入框
password.setBounds(263,87,160,30);
this.getContentPane().add(password);
// 215, 142, 55, 22
//验证码提示
JLabel codeText = new JLabel("验证码");
Font codeFont = new Font(null,1,16);
codeText.setForeground(Color.black);
codeText.setFont(codeFont);
codeText.setBounds(215, 142, 55, 22);
this.getContentPane().add(codeText);
// 291, 133, 100, 30
//验证码的输入框
code.setBounds(291, 133, 100, 30);
this.getContentPane().add(code);
//7.添加背景图片
JLabel background1 = new JLabel(new ImageIcon(" E:\\PicturesSpace\\img\\pictures\\background.png"));
background1.setBounds(0, 0, 633, 423);
this.getContentPane().add(background1);
}
```
你好 路径错了
在Java程序中,对于文件路径的使用有一定要求:
css简单装饰一下页面跟点击出现的窗口
.s{
width:100%;
height:100%;
}
.boxs{
width:300px;
height:510px;
display:none;
position:absolute;
}
.box{
width:300px;
height:100px;
border:1px solid #CCC;
text-align: center;
line-height: 100px;
}
html高仿一下网页右键出现的窗口样式
<div class="s" >
<div class="boxs" id="con">
<div class="box">源代码查询</div>
<div class="box">源代码查询</div>
<div class="box">源代码查询</div>
<div class="box">源代码查询</div>
<div class="box">源代码查询</div>
</div>
</div>
script中,主要是全窗口点击事件。。。详情看下↓
window.oncontextmenu = function(e){ //窗口右键点击事件
var e = e || event; //解决兼容
var X = e.clientX; //鼠标箭头距离网页左窗口边的距离
var Y = e.clientY; //鼠标箭头距离网页上窗口边的距离
con.style.display = "block"; //css中已经隐藏(none),现在(block)显示
con.style.top = Y+"px"; //确定X距离,点击是距离多少出现多少
con.style.left = X+"px"; //确定Y距离,点击是距离多少出现多少
return false; //返回false
}
document.onclick = function(){ //文档点击事件
con.style.display = "none"; //再次隐藏
}