- 博客(0)
- 资源 (12)
- 收藏
- 关注
java注册界面
public class Zhuce {
public Zhuce() {
ZhuceFrame zhuce = new ZhuceFrame();
zhuce.setVisible(true);
}
public static void main(String args[]){
new Zhuce();
}
}
class ZhuceFrame extends JFrame { // 框架类
private Toolkit tool; // Abstract Window Toolkit 的所有实际实现的抽象超类 查询 API
public ZhuceFrame() {
setTitle("用户注册");
tool = Toolkit.getDefaultToolkit();
Dimension ds = tool.getScreenSize();
int w = ds.width;
int h = ds.height;
setBounds((w - 300) / 2, (h - 300) / 2, 300, 400);
setResizable(false);
ZhucePanel rp = new ZhucePanel(this);
add(rp);
}
}
class ZhucePanel extends JPanel implements ActionListener { // 容器类
private JLabel titlelabel, namelabel, pwdlabel1, pwdlabel2, sexlabel,
agelabel, classlabel,interestlabel;
private JTextField namefield, agefield;
private JPasswordField pwdfield1, pwdfield2;
private JButton commitbtn, resetbtn, cancelbtn;
private JRadioButton rbtn1, rbtn2;
private JComboBox combo;
private JCheckBox [] jcbArray={new JCheckBox("电脑"),new JCheckBox("音乐"), new JCheckBox("旅游"),new JCheckBox("购物"),new JCheckBox("运动"),new JCheckBox("其他")};
private Vector v;
private GridBagLayout gbl;
private GridBagConstraints gbc;
private JPanel panel;
private Box box;
2013-06-14
java五子棋
public class GobangGame {
// 定义达到赢条件的棋子数目
private final int WIN_COUNT = 5;
// 定义用户输入的X坐标
private int posX = 0;
// 定义用户输入的X坐标
private int posY = 0;
// 定义棋盘
private Chessboard chessboard;
/**
* 空构造器
*/
public GobangGame() {
}
/**
* 构造器,初始化棋盘和棋子属性
*
* @param chessboard
* 棋盘类
*/
public GobangGame(Chessboard chessboard) {
this.chessboard = chessboard;
}
/**
* 检查输入是否合法。
*
* @param inputStr
* 由控制台输入的字符串。
* @return 字符串合法返回true,反则返回false。
*/
public boolean isValid(String inputStr) {
// 将用户输入的字符串以逗号(,)作为分隔,分隔成两个字符串
String[] posStrArr = inputStr.split(",");
try {
posX = Integer.parseInt(posStrArr[0]) - 1;
posY = Integer.parseInt(posStrArr[1]) - 1;
} catch (NumberFormatException e) {
chessboard.printBoard();
System.out.println("请以(数字,数字)的格式输入:");
return false;
}
// 检查输入数值是否在范围之内
if (posX < 0 || posX >= Chessboard.BOARD_SIZE || posY < 0
|| posY >= Chessboard.BOARD_SIZE) {
chessboard.printBoard();
System.out.println("X与Y坐标只能大于等于1,与小于等于" + Chessboard.BOARD_SIZE
+ ",请重新输入:");
return false;
}
// 检查输入的位置是否已经有棋子
String[][] board = chessboard.getBoa
2013-06-14
Java IO学习文件处理
import java.io.*;
import java.util.*;
public class FileFormatChange {
/**
* 1、创建输入(输出)流对象
* 2、读(写)数据
* 3、关闭输入输出流
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Map<String,List<String>> map = new HashMap<String,List<String>>();
BufferedReader br = null;
try {
Reader in = new FileReader("./files/in.txt");
br = new BufferedReader(in);
String line = null;
while((line = br.readLine())!= null){
//line = "xxxx,北京"
String[] str = line.split(",");
List<String> list = map.get(str[1]);
if(list == null){
list = new ArrayList<String>();
}
list.add(str[0]);
map.put(str[1], list);
}
System.out.println(map);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
2013-06-14
java编写的日历
ublic class JCalendar extends JPanel{
//动态表示年月日
private int year=0;
private int month=0;
private int day=0;
private int first = 0;
//用于标志日历面板是否显示
private static boolean isShow = false;
//主面板
private JPanel Main = new JPanel();
//日面板
private JPanel jPanelDay = new JPanel();
//月面板
private JPanel jPanelMonth = new JPanel();
//月的输入位置
private JTextField Month = new JTextField();
//减少月份
private JButton MonthDown = new JButton();
//增加月份
private JButton MonthUp = new JButton();
private JPanel jPanelButton = new JPanel();
//减少年份
private JButton YearDown = new JButton();
//增加年份
private JButton YearUp = new JButton();
//显示日期的位置
private JLabel Out = new JLabel();
public JLabel Out2 = new JLabel();
private Locale l=Locale.CHINESE;
//主日历
private GregorianCalendar cal=new GregorianCalendar(l);
//星期面板
private JPanel weekPanel=new JPanel();
//天按钮组
private JToggleButton[] days=new JToggleButton[42];
//天面板
private JPanel Days = new JPanel();
//标示
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private JLabel jLabel4 = new JLabel();
private JLabel jLabel5 = new JLabel();
private JLabel jLabel6 = new JLabel();
private JLabel jLabel7 = new JLabel();
//当前选择的天数按钮
private JToggleButton cur=null;
//月份天数数组,用来取得当月有多少天
// 1 2 3 4 5 6 7 8 9 10 11 12
private int[] mm={31,28,31,30,31,30,31,31,30,31,30,31};
//空日期构造函数
public JCalendar() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//带日期设置的构造函数
public JCalendar(int year, int month, int day) {
cal.set(year, month, day);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
2013-06-14
java浏览器
ublic class HTTPBrowserDemo extends JFrame
{
JTextField jtfAddress; //输入html文件地址或网址
JButton jbGo; //转到文件按钮
JTextPane jtpShow; //显示文件
JLabel jlInfo; //提示信息
public HTTPBrowserDemo()
{
super("韩公达制作的html浏览器"); //调用父类构造函数
jtfAddress=new JTextField(20); //实例化地址输入框
jbGo=new JButton("转到"); //实例化转向按钮
jtpShow=new JTextPane(); //实例化显示内容框
jlInfo=new JLabel(); //实例化信息提示标签
JPanel panel=new JPanel(); //实例化面板
panel.add(new JLabel("地址")); //增加组件到面板上
2013-06-14
java计算器
import java.awt.event.*;
public class jisuanqi extends JFrame{
String a;
//声明16个Button
Button [] anjian ={new Button("MC"), new Button("MR"),new Button("MS"), new Button("M+"),new Button("M-"), new Button("←"),new Button("CE"), new Button("C"),new Button("±"), new Button("√"), new Button("7"), new Button("8"),new Button("9"),new Button("/"),new Button("%"), new Button("4"), new Button("5"),new Button("6"), new Button("+"), new Button("-"), new Button("1"),new Button("2"),
new Button("0"), new Button("="),new Button("邵")};
//声明文本框,用于接收数字和计算
TextField numText;
//声明面板容器,用于存放各种按钮
Panel anjianPanel;
//构造方法初始化按钮
public static void main(String[] args){
jisuanqi jisuanqi=new jisuanqi("计数器");
//设置窗口大小
jisuanqi.setBounds(400, 300, 300, 300);
//设置界面属性
jisuanqi.setVisible(true);
}
jisuanqi(String title){
super(title);
//初始化文本框,将文本的值设置为“0”
numText=new TextField("0");
//实例化面板;
anjianPanel=new Panel();
//设置按钮
anjianPanel.setLayout(new GridLayout(5,5,5,5));
//实例化按钮
for(int i=0;i<anjian.length;i++){
//添加事件
anjian[i].addActionListener(new anjianAction());
//将各个按钮添加到面板容器中
anjianPanel.add(anjian[i]);
}
//为文本框添加事件
numText.addTextListener(new TextListener() {
2013-06-14
java写的滚动字幕GUI编程
class ZiMupanel extends JFrame {
public ZiMupanel() {
Container con = this.getContentPane();
// 设置窗口名称
this.setTitle("滚动字幕");
// 设置布局管理器为 null ,方便 面板定位,一般使用null 布局时,将窗口设置不可改变大小
this.setLayout(null);
// 设置窗口位置和大小
this.setBounds(300, 300, 460, 330);
// 设置窗口可见
this.setVisible(true);
// 设置不可改变大小
this.setResizable(false);
// 设置当点击窗口的关闭按钮时退出
// 设置此窗体关闭,滚动面板不关闭 this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Panelfont1 p1 = new Panelfont1();
con.add(p1);
p1.setBounds(15, 15, 175, 60);
Panelfont2 p2 = new Panelfont2();
con.add(p2);
p2.setBounds(195, 15, 250, 60);
Panelneizi p3 = new Panelneizi();
con.add(p3);
p3.setBounds(15, 80, 175, 80);
Paneldirection p4 = new Paneldirection();
con.add(p4);
p4.setBounds(195, 80, 250, 80);
Panel5 p5 = new Panel5();
con.add(p5);
p5.setBounds(15, 155, 430, 70);
Panel6 p6 = new Panel6();
con.add(p6);
p6.setBounds(15, 220, 430, 70);
}
}
class Panelfont1 extends JPanel implements ActionListener{
public Panelfont1() {
this.setBorder(BorderFactory.createTitledBorder("滚动字幕的文字大小控制"));//设置 面板边框
this.setLayout(new GridLayout(1, 2));
bigfont = new JRadioButton("大字体", false);
smallfont = new JRadioButton("小字体", true);
bigfont.addActionListener(this);
smallfont.addActionListener(this);
ButtonGroup sexRadioButtonGroup = new ButtonGroup();// 创建一个选按钮组
sexRadioButtonGroup.add(bigfont);// 将单选按钮对象添加到按钮组中
sexRadioButtonGroup.add(smallfont);// 将单选按钮对象添加到按钮组中
//Enumeration elements = sexRadioButtonGroup.getElements();// 遍历按钮组中的所有按钮
this.add(bigfont);
this.add(smallfont);
}
public void actionPerformed(ActionEvent e) {
if(bigfont.isSelected()){
fontSize = 50;
}else {
fontSize = 36;
}
Font font = new Font(fontName,Font.BOLD,fontSize);
2013-06-14
java编写的局域网服务器
public class ServerClient
{
// 记录当前所有的用户
private ArrayList<ReceiveMessage> arrayList = new ArrayList<ReceiveMessage>();
public void start()
{
try
{
ServerSocket server = new ServerSocket(9999);
System.out.println("服务器启动");
while (true)
{
// 等待客户端的请求连接:一旦接受成功就会生成客户端的对象
Socket client = server.accept();
System.out.println("一个客户端连接。");
// 创建子线程,完成客户端的数据通信
ReceiveMessage receiveThread = new ReceiveMessage(client,arrayList);
receiveThread.start();
arrayList.add(receiveThread);
}
} catch (IOException e)
{
e.printStackTrace();
System.out.println("服务器启动失败");
}
}
2013-06-14
java编写的弹球小游戏
package org.crazyit.ball;
import java.awt.Image;
import java.io.File;
import javax.imageio.ImageIO;
import java.io.IOException;
/**
* 小球对象
*
* @author yangenxiong yangenxiong2009@gmail.com
* @author Kelvin Mak kelvin.mak125@gmail.com
* @version 1.0
* <br/>网站: <a href="http://www.crazyit.org">疯狂Java联盟</a>
* <br>Copyright (C), 2009-2010, yangenxiong
* <br>This program is protected by copyright laws.
*/
public class Ball extends BallComponent {
// 定义球的竖向速度
private int speedY = 10;
// 定义弹球的横向速度
private int speedX = 8;
// 定义是否在运动
private boolean started = false;
// 定义是否结束运动
private boolean stop = false;
/**
* m 有参数构造器
*
* @param panelWidth
* int 画板宽度
* @param panelHeight
* int 画板高度
* @param offset
* int 位移
* @param path
* String 图片路径
*/
public Ball(int panelWidth, int panelHeight, int offset, String path)
throws IOException {
// 调用父构造器
super(panelWidth, panelHeight, path);
// 设置y坐标
this.setY(panelHeight - super.getImage().getHeight(null) - offset);
}
/**
* 设置横向速度
*
* @param speed
* int 速度
* @return void
*/
public void setSpeedX(int speed) {
this.speedX = speed;
}
/**
* 设置竖向速度
*
* @param speed
* int 速度
* @return void
*/
public void setSpeedY(int speed) {
this.speedY = speed;
}
/**
* 设置是否在运动
*
* @param b
* boolean
* @return void
*/
public void setStarted(boolean b) {
this.started = b;
}
/**
* 设置是否结束运动
*
* @param b
* boolean
* @return void
*/
public void setStop(boolean b) {
this.stop = b;
}
/**
* 返回横向速度
*
* @return int 速度
*/
public int getSpeedX() {
return this.speedX;
}
/**
* 返回竖向速度
*
* @return int 速度
*/
public int getSpeedY() {
return this.speedY;
}
/**
* 是否在运动
*
* @return boolean 是否在运动
*/
public boolean isStarted() {
return this.started;
}
/**
* 是否已经结束运动
*
* @return boolean 是否已经结束运动
*/
public boolean isStop() {
return this.stop;
}
}
2013-06-14
java窗体GUI所有组件学习
整理了Java GUI编程基础知识!
public class AllFrame {
/**
* 这里的代码涉及到 GUI 编程基本面板、基本组件、事件(ActionListener、ChangeListener、MouseListener)
*/
public AllFrame() {
// new 一个主窗体 也可以这样写 new MainFrame();
MainFrame mf = new MainFrame();
}
public static void main(String[] args) {
new AllFrame();
}
// 主窗体 继承 窗体基本格式 类 Jframe 以下弹出窗口均继承 Jframe
class MainFrame extends Jframe implements ActionListener {
JMenuBar menubar = new JMenuBar();;// 菜单条
JMenu jmenu[] = new JMenu[5];// panelMenu,usedMenu1,usedMenu2,layoutMenu,helpMenu;
// 菜单项
JButton closebtn;// 关闭窗体
// 具体的选项
JMenuItem panelitem[] = new JMenuItem[4];
JMenuItem useditem1[] = new JMenuItem[6];
JMenuItem useditem2[] = new JMenuItem[6];
JMenuItem layoutitem[] = new JMenuItem[3];
JMenuItem helpitem = new JMenuItem("关于");
// 菜单中名称
String menu[] = { "面板使用", "常用组件一", "常用组件二", "布局设置", "帮助" };
String pane[] = { "普通面板", "滚动面板", "分割面板", "选项面板" };
String uesd1[] = { "标签", "按钮", "文本框", "文本域", "单选按钮" ,"微调"};
String uesd2[] = { "滑块","复选框", "下拉菜单", "列表", "表格", "树状" };
String layout[] = { "流式布局", "边界布局", "网格布局" };
// Jpanelitem,Jscrollpaneitem,Splitpaneitem,JTabbedpanelitem,
// Jlabelitem,Jbuttonitem,JTextfielditem,JTextareaitem,JRadiobuttonitem,
// JCheckboxitem,JCombomoxitem,Jlistitem,Jtableitem,Jtreeitem,
// Flowlayoutitem,Borderlayoutitem,Girdlayoutitem,
// Helpitem};
public MainFrame() {
this.setTitle("JAVA图型界面学习(GUI)");
// 加载菜单条到窗体中
this.setJMenuBar(menubar);
// 重新设置大小
this.setSize(380, 290);
// 简单的居中方法 在窗体基本格式类 Jframe 中有详细的居中方法
this.setLocationRelativeTo(null);
// 设置关闭窗口
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 调用方法
menu();
// 设置容器
Container con = this.getContentPane();
// 定义一个 标签 “JAVA图型界面学习”
JLabel jl = new JLabel("JAVA图型界面学习");
// 组件 设置字体大小, 其他组件用法相同
jl.setFont(new Font("隶书", Font.BOLD, 24));
// 具体定位 组件名.setBounds(x, y, width, height)
jl.setBounds(30, 30, 280, 50);
// 把标签加到 con 容器中
con.add(jl);
/
2013-06-14
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人