当离开RCP插件区重新回顾一下JFrame窗口程序的标签、页面间的跳转。

完成一个登陆、注册界面。(界面完成后练习输入输出流,将前台的注册信息保存到一个文件夹下的.txt文件中)

首先向通过JFrame写出一个登陆窗体来,然后给注册按钮绑定actionListener监听。

以下为login页面

 package demo;

 import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
//导入必要的包 public class Demo_login extends JFrame{ JTextField jTextField ; //定义文本框组件
JPasswordField jPasswordField; //定义密码框组件
JLabel jLabel1,jLabel2;
JPanel jp1,jp2,jp3;
JButton jb1,jb2,jb3; //创建按钮
public Demo_login(){
jTextField = new JTextField(12);
jPasswordField = new JPasswordField(13);
jLabel1 = new JLabel("用户名");
jLabel2 = new JLabel("密码");
jb1 = new JButton("确认");
jb2 = new JButton("取消");
jb3 = new JButton("注册");
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel(); //设置布局
this.setLayout(new GridLayout(3,1)); jp1.add(jLabel1);
jp1.add(jTextField);//第一块面板添加用户名和文本框 jp2.add(jLabel2);
jp2.add(jPasswordField);//第二块面板添加密码和密码输入框 jp3.add(jb1);
jp3.add(jb2);
jp3.add(jb3);//第三块面板添加确认和取消
jb3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Demo_add();
} public void Demo_add() {
new Demo_add(); }
}); // jp3.setLayout(new FlowLayout());   //因为JPanel默认布局方式为FlowLayout,所以可以注销这段代码.
this.add(jp1);
this.add(jp2);
this.add(jp3); //将三块面板添加到登陆框上面
//设置显示
this.setSize(300, 200);
//this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setTitle("登陆"); }
public static void main(String[] args){
new Demo_login(); }
}

下一步规划注册信息和完成注册界面

 package demo;

 import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField; public class Demo_add extends JFrame{ public static void main(String[] args) {
new Demo_add();
} String [][] arr = new String [100][5];
JLabel id,name,age, gender,introduction;
ButtonGroup bg;
JRadioButton female,male;
JTextArea textArea;
JTextField tf_id,tf_name,tf_age,jf_introduction;
JButton btn_register;
MyPanel jp;
Box box_id,box_name,box_age,box_gender,box_introduction,baseBox; public Demo_add() { setVisible(true);
setSize(400, 450);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
instantiateFunction();
addFunction(); } public void instantiateFunction(){
jp = new MyPanel(new ImageIcon("./src/picture/pic16.jpg").getImage());
baseBox = Box.createVerticalBox();
box_id = Box.createHorizontalBox();
box_name = Box.createHorizontalBox();
box_age = Box.createHorizontalBox();
box_gender = Box.createHorizontalBox();
box_introduction = Box.createHorizontalBox();
btn_register = new JButton("注册");
tf_id = new JTextField(10);
tf_name = new JTextField(10);
tf_age = new JTextField(10);
bg = new ButtonGroup();
female = new JRadioButton("女");
male = new JRadioButton("男");
textArea = new JTextArea(9,20);
listenerFunction(); } /**
* 实现页面跳转和数组传递
* */ public void listenerFunction(){
btn_register.addActionListener(new ActionListener() { @Override
public void actionPerformed(ActionEvent e) { for (int i = 0; i < arr.length; i++) {
//先做一个判断,如果ID不为空,则传过去
if(arr[i][0]==null || arr[i][0].equals("")){
arr[i][0] =tf_id.getText();
arr[i][1] =tf_name.getText();
arr[i][2] =tf_age.getText(); if(male.isSelected()){
arr[i][3] = male.getText();
}else{
arr[i][3] = female.getText();
}
arr[i][4] =textArea.getText(); break;
}
}
new Demo_addMessage(arr); }
});
} public void addFunction(){
add(jp);
box_id.add(new JLabel("ID: "));
box_id.add(tf_id); box_name.add(new JLabel("姓名: "));
box_name.add(tf_name); box_age.add(new JLabel("年龄: "));
box_age.add(tf_age); box_gender.add(new JLabel("性别: "));
bg.add(male);
bg.add(male);
box_gender.add(male);
box_gender.add(female); box_introduction.add(textArea); baseBox.add(Box.createVerticalStrut(15));
baseBox.add(box_id);
baseBox.add(Box.createVerticalStrut(15));
baseBox.add(box_name);
baseBox.add(Box.createVerticalStrut(15));
baseBox.add(box_age);
baseBox.add(Box.createVerticalStrut(15));
baseBox.add(box_gender);
baseBox.add(Box.createVerticalStrut(15));
baseBox.add(new JLabel("个人简介: "));
baseBox.add(box_introduction);
baseBox.add(Box.createVerticalStrut(15));
baseBox.add(btn_register);
jp.add(baseBox); }
} class MyPanel extends JPanel{
Image img;
public MyPanel(Image img) {
this.img = img;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img,0,0, this.getWidth(), this.getHeight(), this);
}
}

正常开发中注册一般会伴随着回显信息的,因为是对JFrame的熟悉所以数据不是来自数据库,我们直接对这个界面中输入的数据回显

 package demo;

 import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable; public class Demo_addMessage extends JFrame { JTable table;
JPanel jp;
//MyDate model;
JTable tabel;
ImageIcon img1,img2,img3; public Demo_addMessage(String [][] arr) {
System.out.println("跳过来了");
setVisible(true);
setSize(500, 500);
setTitle("保存信息界面");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
init(arr); } private void init(String [][] arr) {
//标题数组
String [] columns = {"ID","姓名","年龄","性别","个人简介"}; //项目的相对路径./代表项目名称
/*img1 = new ImageIcon("./src/picture/dm.png");
img2 = new ImageIcon("./src/picture/pic12.jpg");
img3 = new ImageIcon("./src/picture/pic2.jpg");*/
//model = new MyDate(arr,columns);
jp = new JPanel();
table = new JTable(arr,columns);//没有图片时的实例化
//table = new JTable(model);//存在图片时的实例化
table.setRowHeight(20); JScrollPane scrollPanel = new JScrollPane(table);
jp.add(scrollPanel);
add(jp); } }

到这儿JFrame的界面就简单完成了,下一步就是注册界面练习输入输出流。详情关注下一篇随笔~

JFrome 登陆/注册/回显无数据库连接小程序的更多相关文章

  1. JFrome 登陆/注册/回显/输出流小程序之二

  2. 微信小程序 人脸识别登陆模块

    微信小程序---人脸识别登陆的实现 关键词:微信小程序 人脸识别 百度云接口 前言 这是一篇关于一个原创微信小程序开发过程的原创文章.涉及到的核心技术是微信小程序开发方法和百度云人脸识别接口.小程序的 ...

  3. 微信小程序-注册和第一个demo

    第一篇 申请帐号 https://mp.weixin.qq.com/cgi-bin/registermidpage?action=index&lang=zh_CN 这里注册帐号,记得选小程序, ...

  4. Struts2标签<s:checkboxlist>回显问题

    Struts2 checkboxlist回显问题中,说明两种方式,第一种方式很普遍,第二种则是个人根据现有资源加上尝试得来的成果,第二种主要是为个人笔记(其中相关知识点不一一介绍). 一.普通方法: ...

  5. 小程序&app 注册登录、绑定

    前段时间开发中的一款产品,有小程序和app:小程序直接微信登录,app使用手机号+验证码注册,手机号+验证码/密码登录. 用户使用其中一套账号密码即可正常使用,不强制要求完善另一套账号.为避免同一用户 ...

  6. SpEL表达式注入漏洞学习和回显poc研究

    目录 前言 环境 基础学习和回显实验 语法基础 回显实验 BufferedReader Scanner SpEL漏洞复现 低版本SpringBoot中IllegalStateException CVE ...

  7. 微信小程序开发者注册流程

    一,首先打开浏览器,搜索微信公众平台 点击进入,此时还没有注册微信小程序开发账号,我们需要点击注册 进入注册页面,会出现四种账号,我们选择小程序账号 然后根据提示就可以进行注册了 注册时,需填写一下个 ...

  8. 微信小程序之注册和入门

    一.注册 首先,在微信公众平台mp.weixin.qq.com上注册一个帐号. 小程序开放个人开发者申请注册,个人用户可访问微信公众平台,扫码验证个人身份后即可完成小程序帐号申请并进行代码开发. 这里 ...

  9. 微信小程序之微信登陆 —— 微信小程序教程系列(20)

    简介: 微信登陆,在新建一个微信小程序Hello World项目的时候,就可以看到项目中出现了我们的微信头像,其实这个Hello World项目,就有一个简化版的微信登陆.只不过是,还没有写入到咱们自 ...

随机推荐

  1. Linux&shell 之Shell命令进阶

    写在前面:案例.常用.归类.解释说明.(By Jim) 监控程序a.进程查看ps -ef(-e表示系统上运行的所有进程,-f用于扩展输出一些有用的信息列.)ps -efH(-H参数可以将进程组织为分层 ...

  2. BZOJ1044: [HAOI2008]木棍分割

    1044: [HAOI2008]木棍分割 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1580  Solved: 567[Submit][Statu ...

  3. Simplify Path——LeetCode

    Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", ...

  4. Construct Binary Tree from Inorder and Postorder Traversal——LeetCode

    Given inorder and postorder traversal of a tree, construct the binary tree. 题目大意:给定一个二叉树的中序和后续序列,构建出 ...

  5. 暴力求解——UVA 572(简单的dfs)

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  6. 分页过滤SQL求总条数SQL正则

    public static void main(String[] args) throws Exception { String queryForScanUsers_SQL = "selec ...

  7. poj1013

    题目大意:假造的银币 Sally Jones有一些游客给的银币,但是只有11枚是真正的银币(有一枚是假的),从颜色和大小是无法区分真比还是假币的,但是它的重量和真币是不同的,Sally Jones它是 ...

  8. vue实现一个移动端屏蔽滑动的遮罩层

    在扯废话浪费大家的时间之前,先上个代码好了,使用vue实现起来很简单-- <div class="overlayer" @touchmove.stop > </d ...

  9. Business Analysis and Essential Competencies

    Requirements Classification Schema http://files.cnblogs.com/files/happlyonline/BABOK.pptx http://fil ...

  10. memcache实现公共计数器网站

    在反问题的过程中遇到的最近项目.网上查了很多资料并没有完全实现. 因此,要找到适合自己的xmemcache client和memcache关联API和说明,我们发现了一个比较完美的实现. 键类:net ...