展开全部
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
*
* @author Administrator
*/
public class Main {
/**
* @param args
* the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
final Frame f = new Frame("毕业纪念册");// 标题
final JLabel lbl = new JLabel();
f.setSize(600, 400);// 对话框大小
f.setLocation(100, 100);// 对话框初始位置
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
MenuBar mb = new MenuBar();
Menu m1 = new Menu("photolist");
Menu m2 = new Menu("video栏");
MenuItem mi1 = new MenuItem("photo1");
MenuItem mi2 = new MenuItem("open");
mi2.addActionListener(new ActionListener() { // 打开文件夹
public void actionPerformed(ActionEvent e) {
FileDialog fd = new FileDialog(f, "photo open",
FileDialog.LOAD);
fd.show();
String fileName = fd.getDirectory() + fd.getFile();
Icon icon = new ImageIcon(fileName,"");
lbl.setIcon(icon);
}
});
MenuItem mi3 = new MenuItem("photo3");
MenuItem mi4 = new MenuItem("photo4");
MenuItem mi5 = new MenuItem("video1");
MenuItem mi6 = new MenuItem("video2");
m1.add(mi1);
m1.add(mi2);
m1.add(mi3);
m1.add(mi4);
m2.add(mi5);
m2.add(mi6);
mb.add(m1);
mb.add(m2);
f.setMenuBar(mb);
f.add(lbl);
f.show();
}
}
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
/**
*
* @author Administrator
*/
public class Main {
/**
* @param args
* the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
final Frame f = new Frame("毕业纪念册");// 标题
final JLabel lbl = new JLabel();
f.setSize(600, 400);// 对话框大小
f.setLocation(100, 100);// 对话框初始位置
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
MenuBar mb = new MenuBar();
Menu m1 = new Menu("photolist");
Menu m2 = new Menu("video栏");
MenuItem mi1 = new MenuItem("photo1");
MenuItem mi2 = new MenuItem("open");
mi2.addActionListener(new ActionListener() { // 打开文件夹
public void actionPerformed(ActionEvent e) {
FileDialog fd = new FileDialog(f, "photo open",
FileDialog.LOAD);
fd.show();
String fileName = fd.getDirectory() + fd.getFile();
Icon icon = new ImageIcon(fileName,"");
lbl.setIcon(icon);
}
});
MenuItem mi3 = new MenuItem("photo3");
MenuItem mi4 = new MenuItem("photo4");
MenuItem mi5 = new MenuItem("video1");
MenuItem mi6 = new MenuItem("video2");
m1.add(mi1);
m1.add(mi2);
m1.add(mi3);
m1.add(mi4);
m2.add(mi5);
m2.add(mi6);
mb.add(m1);
mb.add(m2);
f.setMenuBar(mb);
f.add(lbl);
f.show();
}
}
2016-04-29
展开全部
删除本地图片和删除文件是一个道理 只要获取到路径path就可以了
path例如: D:\Images\aa.jpg
/**
* 删除 图片
* @param path 图片路径
* @return 删除成功返回true,否则返回false
*/
public boolean deleteImage(String path) {
flag = false;
file = new File(path);
// 路径为文件且不为空则进行删除
if (file.isFile() && file.exists()) {
file.delete();
flag = true;
}
return flag;
}
path例如: D:\Images\aa.jpg
/**
* 删除 图片
* @param path 图片路径
* @return 删除成功返回true,否则返回false
*/
public boolean deleteImage(String path) {
flag = false;
file = new File(path);
// 路径为文件且不为空则进行删除
if (file.isFile() && file.exists()) {
file.delete();
flag = true;
}
return flag;
}
追问
可是这是通过FileDialog文件对话框由自己选择的图片(String fileName = fd.getDirectory() + fd.getFile();),该图片路径怎么在另一个删除类中使用?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询