setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new ActionListener()
{
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
使用上述方法实现的关闭,退出,在别人机器上可以实现,在自己机器上点击关闭后无响应,JDK5.0,都是XP系统,机器一模一样,Why?
谢谢
new ActionListener()
{
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
使用上述方法实现的关闭,退出,在别人机器上可以实现,在自己机器上点击关闭后无响应,JDK5.0,都是XP系统,机器一模一样,Why?
谢谢
解决方案 »
- 高手帮忙看道题
- 求用JAVA做的网络广告系统源代码+文档!交作业的!谢谢了急求!
- [求助]关于System.out.flush();
- 上传附件的问题 下面的函数是判断附件是否存在,但是走到objStream.LoadFromFile(strFileName);退到catch里,在我的机器上是好用的,但是
- 这个程序为什么不出来??
- 调用JTextField 的 setText方法时出现IllegalStateException: Attempt to mutate in notification的异常
- 安装哪个网站的JAVA,功能全?
- 如何知道Tomcat和Apache已经连上了?
- 可以不可以做非矩形的控件
- 向上转型和向下转型的问题?
- 一个关于this和finalize的问题
- 学习一个例子的时候遇到一个问题,不知道如何解决,请高手帮忙
接口也能new吗!
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.filechooser.FileFilter;import com.sun.org.apache.regexp.internal.recompile;public class ZipTest {
public static void main(String[] args) {
ZipFrameTest frame = new ZipFrameTest();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}class ZipFrameTest extends JFrame {
private JTextArea fileText;
private JComboBox fileComb;
public String zipname; public ZipFrameTest() {
setTitle("ZipTest");
setSize(400, 300);
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem openItem = new JMenuItem("Open");
menu.add(openItem);
openItem.addActionListener(new OpenAction());
JMenuItem exitItem = new JMenuItem("Exit");
menu.add(exitItem);
exitItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
menubar.add(menu);
setJMenuBar(menubar);
fileText = new JTextArea();
fileComb = new JComboBox();
fileComb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
loadZipFile((String)fileComb.getSelectedItem());
}
});
add(fileComb, BorderLayout.SOUTH);
add(new JScrollPane(fileText), BorderLayout.CENTER);
}
private class OpenAction implements ActionListener {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File("."));
ExtensionFileFilter filter = new ExtensionFileFilter();
filter.addExtension(".zip");
filter.addExtension(".jar");
filter.setDescription("ZIP archives");
chooser.setFileFilter(filter);
int r = chooser.showOpenDialog(ZipFrameTest.this);
if(r == JFileChooser.APPROVE_OPTION) {
zipname = chooser.getSelectedFile().getPath();
scanZipFile();
}
}
}
public void scanZipFile() {
fileComb.removeAllItems();
try {
ZipInputStream zin = new ZipInputStream(new FileInputStream(zipname));
ZipEntry entry;
try {
while((entry = zin.getNextEntry()) != null) {
fileComb.addItem(entry.getName());
zin.closeEntry();
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public void loadZipFile(String name) {
try {
ZipInputStream zin = new ZipInputStream(new FileInputStream(zipname));
ZipEntry entry;
fileText.setText("");
while((entry = zin.getNextEntry()) != null) {
if(entry.getName().equals(name)) {
BufferedReader in = new BufferedReader(new InputStreamReader(zin));
String line;
while((line = in.readLine()) != null) {
fileText.append(line);
fileText.append("\n");
}
}
zin.closeEntry();
}
zin.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
class ExtensionFileFilter extends FileFilter {
private ArrayList<String> extensions = new ArrayList<String>();
private String description = ""; public void addExtension(String extension) {
if(!extension.startsWith(".")) {
extension = "." + extension;
}
extensions.add(extension.toLowerCase());
}
public void setDescription(String aDescription) {
description = aDescription;
}
@Override
public String getDescription() {
return description;
}
@Override
public boolean accept(File f) {
if(f.isDirectory()) return true;
String name = f.getName().toLowerCase();
for(String e : extensions)
if(name.endsWith(e))
return true;
return false;
}
}