组件开发

Signed-off-by: wangwei <2261850470@qq.com>
方佳明
wangwei 2 years ago
parent f91f51ace0
commit 5c2c00b06c

@ -1,17 +1,36 @@
package joggle; package joggle;
import javax.swing.*; import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.Desktop; import java.awt.Desktop;
import java.io.*; import java.io.*;
public class joggle { public class joggle {
public static boolean open_resource(){ public static class JFileChooserDemo{
public static void fileFilter(JFileChooser fd, String flag){
if(flag == "maindow"){
fd.setFileFilter(new FileNameExtensionFilter("DRC(*.drc)", "drc"));
fd.setAcceptAllFileFilterUsed(false);
}
else{
fd.setFileFilter(new FileNameExtensionFilter("image(*.jpg,*.jpeg,*.png)", "drc"));
fd.setAcceptAllFileFilterUsed(false);
}
}
public static boolean open_resource(){
JFileChooser fd = new JFileChooser(); JFileChooser fd = new JFileChooser();
//fd.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); //fd.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fd.showOpenDialog(null); fileFilter(fd, "mindow");
File f = fd.getSelectedFile(); int val = fd.showOpenDialog(null);
if(f != null){} if(val == fd.APPROVE_OPTION){
return true; fd.getSelectedFile();
return true;
}
else{
return false;
}
}
} }
public static void copyFile(String oldPath, String newPath) { public static void copyFile(String oldPath, String newPath) {
try { try {
int bytesum = 0; int bytesum = 0;

@ -8,7 +8,7 @@ import java.io.*;
//主窗口 //主窗口
public class Main extends menu { public class MainWindow extends menu {
public static JFrame page = new JFrame("主菜单"); public static JFrame page = new JFrame("主菜单");
//创建主窗口 //创建主窗口
public static void main(String[] args) { public static void main(String[] args) {
@ -32,28 +32,27 @@ public class Main extends menu {
//鼠标触发事件 //鼠标触发事件
b.addActionListener(new AbstractAction() { b.addActionListener(new AbstractAction() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
joggle.open_resource(); joggle.JFileChooserDemo.open_resource();
JFileChooser fd = new JFileChooser();
} }
}); });
} }
//打开 //打开
public static void open(){ public static void open(){
JButton b = new JButton("打开"); JButton b = new JButton("打开");
b.setBounds(625,400,250,50); b.setBounds(625,400,250,50);
Container c = page.getContentPane(); Container c = page.getContentPane();
c.setLayout(new FlowLayout()); c.setLayout(new FlowLayout());
c.add(b); c.add(b);
b.setDefaultCapable(true); b.setDefaultCapable(true);
b.setVisible(true); b.setVisible(true);
//鼠标触发事件 //鼠标触发事件
b.addActionListener(new AbstractAction() { b.addActionListener(new AbstractAction() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
joggle.open_resource(); joggle.JFileChooserDemo.open_resource();
joggle.copyFile("C:/Users/wangw/Desktop/英语作文","C:/Users/wangw/Desktop/英语作文"); joggle.copyFile("C:/Users/wangw/Desktop/英语作文","C:/Users/wangw/Desktop/英语作文");
} }
}); });
} }
} }
Loading…
Cancel
Save