JAVA界面学习
2021-10-21 22:57 wwx的个人博客 阅读(116) 评论(0) 收藏 举报package gui;
import java.awt.*;
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.JTextField;
public class GUIontology
{
//对象属性
public class ButListener4 implements ActionListener
{
//定义JTextFieldb变量,用来保存传递过来的文本框对象
private JTextField ExcelPath;
private JTextField OwlPath;
private JTextField ClassCol;
private JTextField IndividualCol;
private JTextField ObjectPropertyCol;
//定义setJt方法,初始化
public void setJt(JTextField ExcelPath,JTextField OwlPath,JTextField ClassCol,JTextField IndividualCol,JTextField ObjectPropertyCol)
{
this.ExcelPath = ExcelPath;
this.OwlPath= OwlPath;
this.ClassCol=ClassCol;
this.IndividualCol=IndividualCol;
this.ObjectPropertyCol=ObjectPropertyCol;
}
public void actionPerformed(ActionEvent e)
{
//检测到按钮被点击自动计入到这个函数,这个函数是ActionListener类的方法
//接下来获取文本框里面的字符串
String excelpath = ExcelPath.getText();
String owlpath=OwlPath.getText();
String classpath=ClassCol.getText();
String individualcol=IndividualCol.getText();
String objectpropertycol=ObjectPropertyCol.getText();
if(!(excelpath.isBlank())&&!(owlpath.isBlank()))
{
Sucess sc=new Sucess();//GIS转换为本体的函数
sc.owlconvert();
}
else
{
//转换失败界面写这里
System.out.println("convert failed !!!");
}
}
public class Sucess
{
public void owlconvert()
{
//转换函数
}
}
}
/*
public class ButListener implements ActionListener
{
//定义JTextFieldb变量jt,用来保存传递过来的文本框对象
private JTextField jt;
private JTextField jt2;
//定义set方法,初始化jt
public void setJt(JTextField jt,JTextField jt2)
{
this.jt = jt;
this.jt2= jt2;
}
public void actionPerformed(ActionEvent e)
{
//检测到按钮被点击自动计入到这个函数,这个函数是ActionListener类的方法
//接下来获取文本框里面的字符串
String name = jt.getText();
String password=jt2.getText();
//验证账号和密码,如果正确显示登陆成功的界面
//账号123对应密码789
if("123".equals(name)&&"789".equals(password))
{
Sucess sc=new Sucess();//新的界面(跟旧的差不多后面有代码)
sc.showUI();
}
else
{
//登录失败界面写这里
}
}
public class Sucess
{
public void showUI()
{
javax.swing.JFrame jf= new javax.swing.JFrame();
jf.setTitle("转换");
jf.setSize(300,400);
jf.setDefaultCloseOperation(3);
jf.setLocationRelativeTo(null);
java.awt.FlowLayout flow=new java.awt.FlowLayout();
jf.setLayout(flow);
javax.swing.ImageIcon icon = new javax.swing.ImageIcon("D:\\Picture\\02.jpg");
javax.swing.JLabel jla= new javax.swing.JLabel(icon);
java.awt.Dimension dm0=new java.awt.Dimension(280,200);
jla.setPreferredSize(dm0);
jf.add(jla);
jf.setVisible(true);
}
}
}
*/
public class Buttonb4 implements ActionListener
{
@SuppressWarnings("null")
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
Frame f0=new Frame("ExceltoOntology");
JLabel ExcelPath=new JLabel("ExcelPath");
JLabel OntologyPath=new JLabel("OwlPath");
JLabel ClassCol=new JLabel("ClassCol");
JLabel IndividualCol=new JLabel("IndividualCol");
JLabel ObjectPropertyCol=new JLabel("ObjectPropertyCol");
Button f0butt=new Button("Convert");
f0.add(ExcelPath);
f0.add(OntologyPath);
f0.add(ClassCol);
f0.add(IndividualCol);
f0.add(ObjectPropertyCol);
f0.add(f0butt);
f0.setSize(300, 240);
f0.setLayout(null);
f0.setVisible(true);
//给按钮添加动作监听器方法
ButListener4 but4 = new ButListener4();
//创建一个监听器
f0butt.addActionListener(but4);
//把监听器加在“Excel转换为本体”按钮上
}
}
//数值属性转换
public class ButListener3 implements ActionListener
{
//定义JTextFieldb变量,用来保存传递过来的文本框对象
private JTextField ExcelPath;
private JTextField OwlPath;
private JTextField ClassCol;
private JTextField IndividualCol;
private JTextField ObjectPropertyCol;
//定义setJt方法,初始化
public void setJt(JTextField ExcelPath,JTextField OwlPath,JTextField ClassCol,JTextField IndividualCol,JTextField ObjectPropertyCol)
{
this.ExcelPath = ExcelPath;
this.OwlPath= OwlPath;
this.ClassCol=ClassCol;
this.IndividualCol=IndividualCol;
this.ObjectPropertyCol=ObjectPropertyCol;
}
public void actionPerformed(ActionEvent e)
{
//检测到按钮被点击自动计入到这个函数,这个函数是ActionListener类的方法
//接下来获取文本框里面的字符串
String excelpath = ExcelPath.getText();
String owlpath=OwlPath.getText();
String classpath=ClassCol.getText();
String individualcol=IndividualCol.getText();
String objectpropertycol=ObjectPropertyCol.getText();
if(!(excelpath.isBlank())&&!(owlpath.isBlank()))
{
Sucess sc=new Sucess();//GIS转换为本体的函数
sc.owlconvert();
}
else
{
//转换失败界面写这里
System.out.println("convert failed !!!");
}
}
public class Sucess
{
public void owlconvert()
{
//转换函数
}
}
}
/*
public class ButListener implements ActionListener
{
//定义JTextFieldb变量jt,用来保存传递过来的文本框对象
private JTextField jt;
private JTextField jt2;
//定义set方法,初始化jt
public void setJt(JTextField jt,JTextField jt2)
{
this.jt = jt;
this.jt2= jt2;
}
public void actionPerformed(ActionEvent e)
{
//检测到按钮被点击自动计入到这个函数,这个函数是ActionListener类的方法
//接下来获取文本框里面的字符串
String name = jt.getText();
String password=jt2.getText();
//验证账号和密码,如果正确显示登陆成功的界面
//账号123对应密码789
if("123".equals(name)&&"789".equals(password))
{
Sucess sc=new Sucess();//新的界面(跟旧的差不多后面有代码)
sc.showUI();
}
else
{
//登录失败界面写这里
}
}
public class Sucess
{
public void showUI()
{
javax.swing.JFrame jf= new javax.swing.JFrame();
jf.setTitle("转换");
jf.setSize(300,400);
jf.setDefaultCloseOperation(3);
jf.setLocationRelativeTo(null);
java.awt.FlowLayout flow=new java.awt.FlowLayout();
jf.setLayout(flow);
javax.swing.ImageIcon icon = new javax.swing.ImageIcon("D:\\Picture\\02.jpg");
javax.swing.JLabel jla= new javax.swing.JLabel(icon);
java.awt.Dimension dm0=new java.awt.Dimension(280,200);
jla.setPreferredSize(dm0);
jf.add(jla);
jf.setVisible(true);
}
}
}
*/
public class Buttonb3 implements ActionListener
{
@SuppressWarnings("null")
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
Frame f0=new Frame("ExceltoOntology");
JLabel ExcelPath=new JLabel("ExcelPath");
JLabel OntologyPath=new JLabel("OwlPath");
JLabel ClassCol=new JLabel("ClassCol");
JLabel IndividualCol=new JLabel("IndividualCol");
JLabel ObjectPropertyCol=new JLabel("ObjectPropertyCol");
Button f0butt=new Button("Convert");
f0.add(ExcelPath);
f0.add(OntologyPath);
f0.add(ClassCol);
f0.add(IndividualCol);
f0.add(ObjectPropertyCol);
f0.add(f0butt);
f0.setSize(300, 240);
f0.setLayout(null);
f0.setVisible(true);
//给按钮添加动作监听器方法
ButListener3 but3 = new ButListener3();
//创建一个监听器
f0butt.addActionListener(but3);
//把监听器加在“Excel转换为本体”按钮上
}
}
//本体合并
public class ButListener2 implements ActionListener
{
//定义JTextFieldb变量,用来保存传递过来的文本框对象
private JTextField ExcelPath;
private JTextField OwlPath;
private JTextField ClassCol;
private JTextField IndividualCol;
private JTextField ObjectPropertyCol;
//定义setJt方法,初始化
public void setJt(JTextField ExcelPath,JTextField OwlPath,JTextField ClassCol,JTextField IndividualCol,JTextField ObjectPropertyCol)
{
this.ExcelPath = ExcelPath;
this.OwlPath= OwlPath;
this.ClassCol=ClassCol;
this.IndividualCol=IndividualCol;
this.ObjectPropertyCol=ObjectPropertyCol;
}
public void actionPerformed(ActionEvent e)
{
//检测到按钮被点击自动计入到这个函数,这个函数是ActionListener类的方法
//接下来获取文本框里面的字符串
String excelpath = ExcelPath.getText();
String owlpath=OwlPath.getText();
String classpath=ClassCol.getText();
String individualcol=IndividualCol.getText();
String objectpropertycol=ObjectPropertyCol.getText();
if(!(excelpath.isBlank())&&!(owlpath.isBlank()))
{
Sucess sc=new Sucess();//GIS转换为本体的函数
sc.owlconvert();
}
else
{
//转换失败界面写这里
System.out.println("convert failed !!!");
}
}
public class Sucess
{
public void owlconvert()
{
//转换函数
}
}
}
/*
public class ButListener implements ActionListener
{
//定义JTextFieldb变量jt,用来保存传递过来的文本框对象
private JTextField jt;
private JTextField jt2;
//定义set方法,初始化jt
public void setJt(JTextField jt,JTextField jt2)
{
this.jt = jt;
this.jt2= jt2;
}
public void actionPerformed(ActionEvent e)
{
//检测到按钮被点击自动计入到这个函数,这个函数是ActionListener类的方法
//接下来获取文本框里面的字符串
String name = jt.getText();
String password=jt2.getText();
//验证账号和密码,如果正确显示登陆成功的界面
//账号123对应密码789
if("123".equals(name)&&"789".equals(password))
{
Sucess sc=new Sucess();//新的界面(跟旧的差不多后面有代码)
sc.showUI();
}
else
{
//登录失败界面写这里
}
}
public class Sucess
{
public void showUI()
{
javax.swing.JFrame jf= new javax.swing.JFrame();
jf.setTitle("转换");
jf.setSize(300,400);
jf.setDefaultCloseOperation(3);
jf.setLocationRelativeTo(null);
java.awt.FlowLayout flow=new java.awt.FlowLayout();
jf.setLayout(flow);
javax.swing.ImageIcon icon = new javax.swing.ImageIcon("D:\\Picture\\02.jpg");
javax.swing.JLabel jla= new javax.swing.JLabel(icon);
java.awt.Dimension dm0=new java.awt.Dimension(280,200);
jla.setPreferredSize(dm0);
jf.add(jla);
jf.setVisible(true);
}
}
}
*/
public class Buttonb2 implements ActionListener
{
@SuppressWarnings("null")
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
Frame f0=new Frame("ExceltoOntology");
JLabel ExcelPath=new JLabel("ExcelPath");
JLabel OntologyPath=new JLabel("OwlPath");
JLabel ClassCol=new JLabel("ClassCol");
JLabel IndividualCol=new JLabel("IndividualCol");
JLabel ObjectPropertyCol=new JLabel("ObjectPropertyCol");
Button f0butt=new Button("Convert");
f0.add(ExcelPath);
f0.add(OntologyPath);
f0.add(ClassCol);
f0.add(IndividualCol);
f0.add(ObjectPropertyCol);
f0.add(f0butt);
f0.setSize(300, 240);
f0.setLayout(null);
f0.setVisible(true);
//给按钮添加动作监听器方法
ButListener2 but2 = new ButListener2();
//创建一个监听器
f0butt.addActionListener(but2);
//把监听器加在“Excel转换为本体”按钮上
}
}
//本体修改
public class ButListener1 implements ActionListener
{
//定义JTextFieldb变量,用来保存传递过来的文本框对象
private JTextField ExcelPath;
private JTextField OwlPath;
private JTextField ClassCol;
private JTextField IndividualCol;
private JTextField ObjectPropertyCol;
//定义setJt方法,初始化
public void setJt(JTextField ExcelPath,JTextField OwlPath,JTextField ClassCol,JTextField IndividualCol,JTextField ObjectPropertyCol)
{
this.ExcelPath = ExcelPath;
this.OwlPath= OwlPath;
this.ClassCol=ClassCol;
this.IndividualCol=IndividualCol;
this.ObjectPropertyCol=ObjectPropertyCol;
}
public void actionPerformed(ActionEvent e)
{
//检测到按钮被点击自动计入到这个函数,这个函数是ActionListener类的方法
//接下来获取文本框里面的字符串
String excelpath = ExcelPath.getText();
String owlpath=OwlPath.getText();
String classpath=ClassCol.getText();
String individualcol=IndividualCol.getText();
String objectpropertycol=ObjectPropertyCol.getText();
if(!(excelpath.isBlank())&&!(owlpath.isBlank()))
{
Sucess sc=new Sucess();//GIS转换为本体的函数
sc.owlconvert();
}
else
{
//转换失败界面写这里
System.out.println("convert failed !!!");
}
}
public class Sucess
{
public void owlconvert()
{
//修改函数
}
}
}
/*
public class ButListener implements ActionListener
{
//定义JTextFieldb变量jt,用来保存传递过来的文本框对象
private JTextField jt;
private JTextField jt2;
//定义set方法,初始化jt
public void setJt(JTextField jt,JTextField jt2)
{
this.jt = jt;
this.jt2= jt2;
}
public void actionPerformed(ActionEvent e)
{
//检测到按钮被点击自动计入到这个函数,这个函数是ActionListener类的方法
//接下来获取文本框里面的字符串
String name = jt.getText();
String password=jt2.getText();
//验证账号和密码,如果正确显示登陆成功的界面
//账号123对应密码789
if("123".equals(name)&&"789".equals(password))
{
Sucess sc=new Sucess();//新的界面(跟旧的差不多后面有代码)
sc.showUI();
}
else
{
//登录失败界面写这里
}
}
public class Sucess
{
public void showUI()
{
javax.swing.JFrame jf= new javax.swing.JFrame();
jf.setTitle("转换");
jf.setSize(300,400);
jf.setDefaultCloseOperation(3);
jf.setLocationRelativeTo(null);
java.awt.FlowLayout flow=new java.awt.FlowLayout();
jf.setLayout(flow);
javax.swing.ImageIcon icon = new javax.swing.ImageIcon("D:\\Picture\\02.jpg");
javax.swing.JLabel jla= new javax.swing.JLabel(icon);
java.awt.Dimension dm0=new java.awt.Dimension(280,200);
jla.setPreferredSize(dm0);
jf.add(jla);
jf.setVisible(true);
}
}
}
*/
public class Buttonb1 implements ActionListener
{
@SuppressWarnings("null")
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
Frame f0=new Frame("ExceltoOntology");
JLabel ExcelPath=new JLabel("ExcelPath");
JLabel OntologyPath=new JLabel("OwlPath");
JLabel ClassCol=new JLabel("ClassCol");
JLabel IndividualCol=new JLabel("IndividualCol");
JLabel ObjectPropertyCol=new JLabel("ObjectPropertyCol");
Button f0butt=new Button("Convert");
f0.add(ExcelPath);
f0.add(OntologyPath);
f0.add(ClassCol);
f0.add(IndividualCol);
f0.add(ObjectPropertyCol);
f0.add(f0butt);
f0.setSize(300, 240);
f0.setLayout(null);
f0.setVisible(true);
//给按钮添加动作监听器方法
ButListener1 but1 = new ButListener1();
//创建一个监听器
f0butt.addActionListener(but1);
//把监听器加在“Excel转换为本体”按钮上
}
}
public class ButListener0 implements ActionListener
{
//定义JTextFieldb变量,用来保存传递过来的文本框对象
private JTextField ExcelPath;
private JTextField OwlPath;
private JTextField ClassCol;
private JTextField IndividualCol;
private JTextField ObjectPropertyCol;
//定义setJt方法,初始化
public void setJt(JTextField ExcelPath,JTextField OwlPath,JTextField ClassCol,JTextField IndividualCol,JTextField ObjectPropertyCol)
{
this.ExcelPath = ExcelPath;
this.OwlPath= OwlPath;
this.ClassCol=ClassCol;
this.IndividualCol=IndividualCol;
this.ObjectPropertyCol=ObjectPropertyCol;
}
public void actionPerformed(ActionEvent e)
{
//检测到按钮被点击自动计入到这个函数,这个函数是ActionListener类的方法
//接下来获取文本框里面的字符串
String excelpath = ExcelPath.getText();
String owlpath=OwlPath.getText();
String classpath=ClassCol.getText();
String individualcol=IndividualCol.getText();
String objectpropertycol=ObjectPropertyCol.getText();
if(!(excelpath.isBlank())&&!(owlpath.isBlank()))
{
Sucess sc=new Sucess();//GIS转换为本体的函数
sc.owlconvert();
}
else
{
//转换失败界面写这里
System.out.println("convert failed !!!");
}
}
public class Sucess
{
public void owlconvert()
{
//转换函数
}
}
}
/*
public class ButListener implements ActionListener
{
//定义JTextFieldb变量jt,用来保存传递过来的文本框对象
private JTextField jt;
private JTextField jt2;
//定义set方法,初始化jt
public void setJt(JTextField jt,JTextField jt2)
{
this.jt = jt;
this.jt2= jt2;
}
public void actionPerformed(ActionEvent e)
{
//检测到按钮被点击自动计入到这个函数,这个函数是ActionListener类的方法
//接下来获取文本框里面的字符串
String name = jt.getText();
String password=jt2.getText();
//验证账号和密码,如果正确显示登陆成功的界面
//账号123对应密码789
if("123".equals(name)&&"789".equals(password))
{
Sucess sc=new Sucess();//新的界面(跟旧的差不多后面有代码)
sc.showUI();
}
else
{
//登录失败界面写这里
}
}
public class Sucess
{
public void showUI()
{
javax.swing.JFrame jf= new javax.swing.JFrame();
jf.setTitle("转换");
jf.setSize(300,400);
jf.setDefaultCloseOperation(3);
jf.setLocationRelativeTo(null);
java.awt.FlowLayout flow=new java.awt.FlowLayout();
jf.setLayout(flow);
javax.swing.ImageIcon icon = new javax.swing.ImageIcon("D:\\Picture\\02.jpg");
javax.swing.JLabel jla= new javax.swing.JLabel(icon);
java.awt.Dimension dm0=new java.awt.Dimension(280,200);
jla.setPreferredSize(dm0);
jf.add(jla);
jf.setVisible(true);
}
}
}
*/
public class Buttonb implements ActionListener
{
@SuppressWarnings("null")
@Override
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
Frame f0=new Frame("ExceltoOntology");
JLabel ExcelPath=new JLabel("ExcelPath");
JLabel OntologyPath=new JLabel("OwlPath");
JLabel ClassCol=new JLabel("ClassCol");
JLabel IndividualCol=new JLabel("IndividualCol");
JLabel ObjectPropertyCol=new JLabel("ObjectPropertyCol");
Button f0butt=new Button("Convert");
f0.add(ExcelPath);
f0.add(OntologyPath);
f0.add(ClassCol);
f0.add(IndividualCol);
f0.add(ObjectPropertyCol);
f0.add(f0butt);
f0.setSize(300, 240);
f0.setLayout(null);
f0.setVisible(true);
//给按钮添加动作监听器方法
ButListener0 but0 = new ButListener0();
//创建一个监听器
f0butt.addActionListener(but0);
//把监听器加在“Excel转换为本体”按钮上
}
}
public static void main(String[] args)
{
Frame f=new Frame("OntologyGUI");
Button b=new Button("Excel转换为本体");
Button b1=new Button("本体修改");
Button b2=new Button("本体合并");
Button b3=new Button("GIS属性表到本体数值属性转换");
Button b4=new Button("GIS属性表到本体对象属性转换");
b.setBounds(50, 30, 150, 30);
b1.setBounds(50, 70, 150, 30);
b2.setBounds(50, 110, 150, 30);
b3.setBounds(35, 150, 180, 30);
b4.setBounds(35, 190, 180, 30);
f.add(b);f.add(b1);f.add(b2);f.add(b3);f.add(b4);
f.setSize(300, 240);
f.setLayout(null);
f.setVisible(true);
//ExceltoOntology
Buttonb bnb0=null;
b.addActionListener(bnb0);
ButListener1 but1=null;
b1.addActionListener(but1);
ButListener2 but2=null;
b2.addActionListener(but2);
ButListener3 but3=null;
b3.addActionListener(but3);
ButListener4 but4=null;
b4.addActionListener(but4);
}
class ButtonFrame extends JFrame
{
private JPanel buttonPanel;
public ButtonFrame()
{
setSize(300,200);
//create buttons
JButton yellowButton = new JButton("Yellow");
JButton blueButton=new JButton("Blue");
JButton redButton=new JButton("Red");
/*
由于不能将组件加入到JFrame中,我们使用JPanel(一个面板容器类,可以放按钮、图片、标签等)作为中间容器,
然后再将JPanel置为JFrame的内容
*/
buttonPanel=new JPanel();
//add buttons to panel
buttonPanel.add(yellowButton);
buttonPanel.add(blueButton);
buttonPanel.add(redButton);
//add panel to frame
add(buttonPanel);
//create button actions
ColorAction yellowAction = new ColorAction(Color.YELLOW);
ColorAction blueAction = new ColorAction(Color.BLUE);
ColorAction redAction = new ColorAction(Color.RED);
//associate actions with buttons
yellowButton.addActionListener(yellowAction);
blueButton.addActionListener(blueAction);
redButton.addActionListener(redAction);
}
//当按钮被点击时,将面板的颜色设置为指定的颜色,这个颜色存储在监听器类中
private class ColorAction implements ActionListener
{
private Color backgroundColor;
public ColorAction(Color c)
{
backgroundColor = c;
}
public void actionPerformed(ActionEvent event)
{
//ActionEvent对应按钮点击、菜单选择、选择列表项或在文本框中ENTER
buttonPanel.setBackground((backgroundColor));
}
}
//按钮监听器的父类ActionListener里面有函数可以直接检测按钮是否被点击
}
}
浙公网安备 33010602011771号