Java界面
JFrame.java
package myProject;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.Font;
import java.io.IOException;
public class JFrame extends javax.swing.JFrame {
private JPanel contentPane;
private JTextArea textArea;
public static void main(String[] args) throws IOException{
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
JFrame frame = new JFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public JFrame() {
setTitle("Group5+");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(100, 100, 800, 600);// frame size
contentPane = new JPanel();
contentPane.setLayout(null);
this.getContentPane().add(contentPane);//
//show buttons
controlPanel();
//show create test area
TextArea();
//show create map
Map();
//create hr
createLine();
}
public void Map(){
// map label
JLabel map = new JLabel("Map");
map.setFont(new Font("Arial Black", Font.PLAIN, 18));
map.setBounds(400, 80, 200, 20);
contentPane.add(map);
}
public void TextArea(){
//status testarea
JLabel status = new JLabel("Status");
status.setFont(new Font("Arial Black", Font.PLAIN, 18));
status.setBounds(20, 300, 200, 20);
contentPane.add(status);
}
public void createLine(){
JSeparator line1 = new JSeparator();
//position
line1.setBounds(15, 280, 330, 1);
//color
line1.setForeground(Color.black);
//add
contentPane.add(line1);
JSeparator infoLine = new JSeparator();
//position
infoLine.setBounds(15, 60, 700, 1);
//color
infoLine.setForeground(Color.black);
//add
contentPane.add(infoLine);
}
public void controlPanel(){
//control panel
JLabel controlPanel = new JLabel("Control Panel");
controlPanel.setFont(new Font("Arial Black", Font.PLAIN, 18));
controlPanel.setBounds(20, 80, 180, 20);
contentPane.add(controlPanel);
// button_up
Button button_up = new Button("添加",contentPane);
button_up.go();
button_up.setSize(150,120,80,35);
contentPane.add(button_up.getButton());
// button_down
Button button_down = new Button("查询/修改",contentPane);
button_down.go();
button_down.setSize(150,220,80,35);
contentPane.add(button_down.getButton());
// button_left
Button button_left = new Button("¡û",contentPane);
button_left.go();
button_left.setSize(50,173,80,35);
contentPane.add(button_left.getButton());
// button_right
Button button_right = new Button("¡ú",contentPane);
button_right.go();
button_right.setSize(255,173,80,35);
contentPane.add(button_right.getButton());
}
}
Button.java
package myProject;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Button {
private String content;
private JButton button;
JTextField textField;
private JPanel contentPane;
public Button(String content,JPanel contentPane) {
this.content = content;
this.button = new JButton(content);
this.contentPane = contentPane;
initialTextField();
}
public void initialTextField(){
textField = new JTextField();
textField.setBounds(50, 350, 300, 80);
contentPane.add(textField);
textField.setColumns(10);
}
public String getText() {
return content;
}
public JButton getButton() {
return button;
}
public void setSize(int x, int y, int width, int height) {
this.button.setBounds(x, y, width, height);
}
public void go() {
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// onclick function
switch (button.getText()) {
case "↑":
System.out.println("123");
break;
case "↓":
System.out.println("123");
break;
default:
System.out.println("button error");
break;
}
}
});
}
}
Java界面的更多相关文章
- Java界面设计 Swing(1)
Java界面设计的用途 开发者可以通过Java SE开发丰富并且强大的具有图形界面的桌面应用程序.也可以设计一些提高效率的工具软件,帮助自己处理机械性工作. Java 的图形界面工具包,可以用于工具类 ...
- Java界面程序实现图片的放大缩小
Java界面程序实现图片的放大缩小.这个程序简单地实现了图片的打开.保存.放大一倍.缩小一倍和固定缩放尺寸,但是并没有过多的涵盖对图片的细节处理,只是简单地实现了图片大小的放缩. 思维导图如下: 效果 ...
- JAVA 界面 - 记事本
代码: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Jiemian10 extends ...
- Java界面编程-建立一个可以画出图形的简单框架
引子:总共使用3个.java文件,建立一个简单界面编程的框架. 第1个文件:NotHelloWorldComponent.java //NotHelloWorldComponent.java 1 im ...
- Java界面编程—事件监听机制
组件首先要先注册事件处理器,当用户单击组件.移动鼠标或者敲击键盘时都会产生事件(Event),一旦有时间发生,应用程序就会做出对该事件的响应,这些组件就是事件源(Event source). 接受.解 ...
- Java界面设计
---------------siwuxie095 Java SE(Java Standard Edition) 即 Java 标准版, 一般也 ...
- Java 界面编程【03】事件监听
当你把界面都设计好了,总需要添加相应的执行动作给组件,在JAVA中有相应的时间处理机制,叫做“监听器”,给组件添加相应执行动作的过程叫做“注册”,其中的“监听器”是一个接口,里面包含了相应的执行函数, ...
- 关于一个查询的JAVA界面,希望对你有启发
package work2; import java.awt.BorderLayout; import javax.swing.JButton; import javax.swing.JFrame; ...
- java界面--WePush-master 项目跑起来 -碰到的问题
仅能在IntelliJ里面打开GUI Form文件来进行界面的拖拽设计--eclipse中也可以了 当eclipse 打开.form文件时,提示有.对应的编辑工具可以打开它,请到市场去安装 但是:本人 ...
随机推荐
- 如何防止sql注入
注入法: 从理论上说,认证网页中会有型如: select * from admin where username='XXX' and password='YYY' 的语句,若在正式运行此句之前,如果没 ...
- android 编译过程
引用:http://www.cnblogs.com/devinzhang/archive/2011/12/20/2294686.html http://blog.sina.com.cn/s/blog_ ...
- IP釋放、清除、以及刷新DNS
Windows 10 於桌面按住 Windows + X 按鍵. 選擇 Command Prompt (以管理員執行). 在彈跳視窗中輸入 ipconfig /release. 等待數秒回報此 IP ...
- c#-快速排序-算法
快速排序使用分治法(Divide and conquer)策略来把一个串行(list)分为两个子串行(sub-lists). 步骤为: 1.从数列中挑出一个元素,称为 "基准"(p ...
- java.sql.SQLException: Incorrect key file for table 'C:\Windows\TEMP\#sql578_6e2_68d.MYI'; try to repair it
java.sql.SQLException: Incorrect key file for table 'C:\Windows\TEMP\#sql578_6e2_68d.MYI'; try to re ...
- Javascript之confirm的用法
confirm函数 confirm函数用于提供确认功能,它首先显示给定的message参数所包含的信息,并提供两个可选择的回答“ok”和“cancel”,然后等待用户选择其中的一个.如果用户选择“ok ...
- LDD3 字符设备驱动简单分析
最近在看LDD3,理解了一下,为了加深自己的印象,自己梳理一下.我用的CentOS release 6.6 (Final)系统. 一.编写编译内核模块的Makefile 以下是我用的Makefile ...
- 二十三、Java基础--------网络编程
Java中另一个重要技术就是网络编程了,为了更好的学习web方向的知识,有必要对java之网络编程好好学习,本文将围绕网络编程技术进行分析. 常见的网络协议:UDP.TCP UDP 1. 将数据源和目 ...
- 学习笔记:MySQL列属性
列属性 a) null|not null 缺省值是null,也就是允许为空,如果是not null而又没有给该字段赋值的话,系统会首先查询该字段有没有默认值 b) de ...
- Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片
Android中仿淘宝首页顶部滚动自定义HorizontalScrollView定时水平自动切换图片 自定义ADPager 自定义水平滚动的ScrollView效仿ViewPager 当遇到要在Vie ...