Java-Swing的提升
来源:互联网 发布:平价好用的精华知乎 编辑:程序博客网 时间:2024/06/01 08:54
之前听朋友说过,要我把swing的控件分别写成一个类,再组合成一个界面,昨天试了一下,果然好用:
//主类
//主类
package com.project.view2;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import com.project.prompt2.*;
public class FL_Date_Check extends JFrame implements ActionListener{
Appyle_Exit Ekm;
Date_gui Tmp,Tmpx;
public FL_Date_Check(){
setLayout(new GridLayout(3, 1));
Tmp = new Date_gui();
Tmpx = new Date_gui();
Ekm = new Appyle_Exit("fl_tk");
Ekm.setFl_tmp(this);
add(Tmp.showBorder3(new TitledBorder("开始日期")));
add(Tmpx.showBorder3(new TitledBorder("结束日期")));
add(Ekm.showBorder4(new TitledBorder("最终信息")));
int width = 250;
int height = 270;
this.setSize(width,height);
Toolkit tk = this.getToolkit();
Dimension dm = tk.getScreenSize();
this.setLocation((int)(dm.getWidth()-width)/2,(int)(dm.getHeight()-height)/2);
this.setResizable(false);
this.setVisible(true);
}
public static void main(String[] args) {
new FL_Date_Check();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(Ekm.getJB1())){
System.out.println("+++++++++++++++++++++++++++++++++");
String Comx = (String) Tmp.getCom1().getSelectedItem();
String Comy = (String) Tmp.getCom2().getSelectedItem();
String Comz = (String) Tmp.getCom3().getSelectedItem();
System.out.println("开始日期:"+Comx+" ++ "+Comy+" ++ "+Comz);
String Comx1 = (String) Tmpx.getCom1().getSelectedItem();
String Comy1 = (String) Tmpx.getCom2().getSelectedItem();
String Comz1 = (String) Tmpx.getCom3().getSelectedItem();
System.out.println("结束日期:"+Comx1+" ++ "+Comy1+" ++ "+Comz1);
}else if (e.getSource().equals(Ekm.getJB2())){
System.out.println("取消");
}
}
}
//日期类
package com.project.prompt2;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import com.project.tools.*;
public class Date_gui extends JFrame{
JLabel JL1,JL2;
JComboBox com1,com2,com3;
public JPanel showBorder3(Border b) {
JPanel jp = new JPanel();
jp.setLayout(new GridLayout(1,3,5,5));
String xk = Cam_All_Info.Time_Now;
String[] strarray=xk.split("");
String[] strarrax=xk.split("-");
JPanel jp2 = new JPanel();
jp2.setLayout(new FlowLayout());
Vector<String> tempu=new Vector<String>();
tempu.add(strarrax[0]);
tempu.add("2015");
tempu.add("2016");
tempu.add("2017");
tempu.add("2018");
com1 = new JComboBox<String>(tempu);
com1.setFocusable(false);
com1.setOpaque(false);
com1.setBackground(Color.white);
com1.setFont(MyTools.f2);
jp2.add(com1);
JPanel jp3 = new JPanel();
jp3.setLayout(new FlowLayout());
Vector<String> tempx=new Vector<String>();
tempx.add(strarrax[1]);
for (int i = 1;i < 13;i++)
{
if(i < 10){
String Tmp = String.valueOf(i);
tempx.add(0+Tmp);
}else{
String Tmp = String.valueOf(i);
tempx.add(Tmp);
}
}
com2 = new JComboBox<String>(tempx);
com2.setFocusable(false);
com2.setOpaque(false);
com2.setBackground(Color.white);
com2.setFont(MyTools.f2);
jp3.add(com2);
JPanel jp4 = new JPanel();
jp4.setLayout(new FlowLayout());
Vector<String> tempy=new Vector<String>();
String[] strarraz= strarrax[2].split(" ");
tempy.add(strarraz[0]);
for (int i = 1;i < 32;i++)
{
if(i < 10){
String Tmp = String.valueOf(i);
tempy.add(0+Tmp);
}else{
String Tmp = String.valueOf(i);
tempy.add(Tmp);
}
}
com3 = new JComboBox<String>(tempy);
com3.setFocusable(false);
com3.setOpaque(false);
com3.setBackground(Color.white);
com3.setFont(MyTools.f2);
jp4.add(com3);
jp.add(jp2);
jp.add(jp3);
jp.add(jp4);
jp.setBorder(b);
return jp;
}
public JComboBox getCom1() {
return com1;
}
public void setCom1(JComboBox com1) {
this.com1 = com1;
}
public JComboBox getCom2() {
return com2;
}
public void setCom2(JComboBox com2) {
this.com2 = com2;
}
public JComboBox getCom3() {
return com3;
}
public void setCom3(JComboBox com3) {
this.com3 = com3;
}
}
//确定应用类
package com.project.prompt2;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import com.project.view2.FL_Date_Check;
public class Appyle_Exit extends JFrame implements ActionListener{
JButton JB1,JB2;
JLabel JL1,JL2,JL3,JL4;
String Type_Tmp;
FL_Date_Check Fl_tmp;
public Appyle_Exit(String Type_Tmp)
{
this.Type_Tmp=Type_Tmp;
}
public JPanel showBorder4(Border b) {
JPanel jp = new JPanel();
JB1 = new JButton(" 确定(Y) ");
JB1.addActionListener(this);
JL4 = new JLabel( " " );
JB2 = new JButton(" 取消(N)");
JB2.addActionListener(this);
jp.add(JB1);
jp.add(JL4);
jp.add(JB2);
return jp;
}
public void actionPerformed(ActionEvent e) {
if (Type_Tmp.equals("fl_tk")){
Fl_tmp.actionPerformed(e);
}
}
public FL_Date_Check getFl_tmp() {
return Fl_tmp;
}
public void setFl_tmp(FL_Date_Check fl_tmp) {
Fl_tmp = fl_tmp;
}
public JButton getJB1() {
return JB1;
}
public void setJB1(JButton jB1) {
JB1 = jB1;
}
public JButton getJB2() {
return JB2;
}
public void setJB2(JButton jB2) {
JB2 = jB2;
}
}
结果如下:
0 0
- Java-Swing的提升
- Java版拼图游戏(基于swing编程提升版)
- java--Swing的春天
- java的Swing编程
- java swing的拖放例子
- 初学 java的swing控件
- JAVA Swing实现的clock
- JAVA中SWing的作用?
- Java swing 做的东西
- Java Swing系统托盘的使用
- Java Swing系统托盘的使用
- 关于java swing的学习
- java的awt和swing
- java.swing的一点积累
- java Swing 文本框的使用
- java swing的一些知识点
- java Swing JFileChooser 的使用
- java swing的版面结构
- 开源 免费 java CMS - FreeCMS1.9 会员管理
- oracle备忘单一
- JAVA语言如何进行异常处理,关键字:throws,throw,try,catch,finally分别代表什么意义?在try块中可以抛出异常吗
- DataUml Design 教程6-DataUML Design 1.1版本正式发布(支持PD数据模型)
- 算法练习1
- Java-Swing的提升
- android 通过Intent使用Bundle传递对象
- 链表逆序输出
- 【C语言天天练(零)】a.out简介
- java中有几种方法可以实现一个线程?用什么关键字修饰同步方法? stop()和suspend()方法为何不推荐使用
- 闲谈系统架构
- 补第三周作业:冒泡排序法
- oracle备忘录-注入
- spring定时器的实现方式-TimerTask 实现方式