JFrame基本操作,增加选择文件按钮

更新时间:2023-07-14 03:26:02 阅读: 评论:0

JFrame基本操作,增加选择⽂件按钮//继承JFrame,将该对象变成⾯板,实现ActionListener实现按钮监听
public class Frame extends JFrame implements ActionListener{
//窗⼝
JFrame jf = new JFrame("王狗蛋的⼩助⼿");
//画板
JPanel jp = new JPanel();
//布局卡选项
JTabbedPane tabPane=new JTabbedPane();
//布局1
Container con=new Container();
//标签
JLabel jl1 = new JLabel("选择数据源");
JLabel jl2 = new JLabel("选择模板");
JLabel jl3 = new JLabel("选择输出⽬录");
//按钮
JButton jb1 = new JButton("···");
JButton jb2 = new JButton("···");
JButton jb3 = new JButton("···");
JButton jb4 = new JButton("启动程序");
//⽂本
JTextArea jt1 = new JTextArea();
JTextArea jt2 = new JTextArea();
JTextArea jt3 = new JTextArea();
//⽂件选择器
JFileChoor choor = new JFileChoor();
public Frame(){
//将画板加到窗⼝上
jf.add(jp);
//布局,将布局卡加到⾯板上
jf.tContentPane(tabPane);
//设置标签,按钮,⽂本框的位置及⼤⼩,x,y,width,height
jl1.tBounds(20,20, 100, 20);
jb1.tBounds(640,20,50,20);
jt1.tBounds(120,20,500,20);
jl2.tBounds(20,50, 100, 20);
jb2.tBounds(640,50,50,20);
jt2.tBounds(120,50,500,20);
jl3.tBounds(20,80, 100, 20);
jb3.tBounds(640,80,50,20);
jt3.tBounds(120,80,500,20);
jb4.tBounds(300,140,100,30);
//设置按钮事件处理  this代表本⾝这个对象,意思是监听这个对象,所⾥该类必须实现ActionListener
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
jb4.addActionListener(this);
//将按钮加到布局1上
con.add(jl1);
con.add(jt1);
con.add(jb1);
con.add(jl2);
con.add(jt2);
con.add(jb2);
con.add(jl3);
con.add(jt3);
con.add(jb3);
合肥二本院校con.add(jb4);
//将布局加到布局卡内,并设置该布局的名称
tabPane.add("⽣成excel",con);
//设置窗⼝属性---------------------
//窗⼝可见
jf.tVisible(true);
大白兔奶糖广告//窗⼝⼤⼩
jf.tSize(800, 400);
//关闭窗⼝时关闭程序
jf.tDefaultCloOperation(EXIT_ON_CLOSE);
/
/设置窗⼝位置
jf.tLocation(400, 150);
}
public static void main(String[] args) {
//创建该对象则调⽤构造⽅法,对象实现ActionListener则⾃动调⽤actionPerformed()⽅法 Frame f = new Frame();
}
//事件处理,所有事件处理必须写在该⽅法,该⽅法重写⾃ActionListener
@Override老公英语怎么写
public void actionPerformed(ActionEvent e) {
//点击按钮后,判断是哪⼀个按钮
Source() == jb1){
//设置⽂件选择器只能选择0(⽂件),1(⽂件夹)
choor.tFileSelectionMode(0);
//打开⽂件浏览器,点击取消则返回1
int status = choor.showOpenDialog(null);
if(status == 1){
return;
}el{
//读取选择器选择到的⽂件
File file = SelectedFile();
//获取⽂件绝对路径并写⼊到⽂本框内
jt1.AbsolutePath());
}
}
Source() == jb2){
虾尾怎么炒
choor.tFileSelectionMode(0);
int status = choor.showOpenDialog(null);
if(status == 1){
return;
}el{
File file = SelectedFile();
jt2.AbsolutePath());
口头交流}
月经量少怎么回事
}
Source() == jb3){
choor.tFileSelectionMode(1);
int status = choor.showOpenDialog(null);
if(status == 1){
return;
}el{
File file = SelectedFile(); jt3.AbsolutePath()); }
}
Source() == jb4){
Main m = new Main();
电商运营try {
m.start();
} catch (Exception e1) {
//准备添加错误⽇志报告写⼊⽂件
e1.printStackTrace();
}
}
小学语文4年级}
}

本文发布于:2023-07-14 03:26:02,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1095414.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:按钮   选择   对象   设置   实现
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图