package com.yunlan.mailquery;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
class Display implements ActionListener{
private JTextArea area = new JTextArea();
private JFrame frame = new JFrame("邮件查询");
private JButton save = new JButton("保存");
private JButton exit = new JButton("退出");
private JLabel label = new JLabel("请输入地址");
private JPanel buttonPanel = new JPanel();
// private JPanel upPanel = new JPanel(new BorderLayout());
private JPanel upPanel = new JPanel();
private JPanel textbutton = new JPanel();
private JTextArea addressText = new JTextArea(2,1);
private JButton queryButton = new JButton("查询");
private JButton clearButton = new JButton("清空");
public Display(){
upPanel.setLayout(new BorderLayout(3,3));
this.upPanel.add(this.label,BorderLayout.NORTH);
this.textbutton.add(this.queryButton);
this.textbutton.add(this.clearButton);
this.upPanel.add(this.addressText,BorderLayout.CENTER);
this.upPanel.add(this.textbutton,BorderLayout.EAST);
this.buttonPanel.add(exit);
this.buttonPanel.add(save);
this.addressText.setLineWrap(true);
frame.setLayout(new BorderLayout(3,3));
frame.add(this.upPanel, BorderLayout.NORTH);
frame.add(this.buttonPanel, BorderLayout.SOUTH);
frame.add(new JScrollPane(this.area),BorderLayout.CENTER);
this.frame.setLocation(400, 250);
this.frame.setSize(500,300);
this.frame.setVisible(true);
this.frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(1);
}
});
this.exit.addActionListener(this);
this.save.addActionListener(this);
this.queryButton.addActionListener(this);
this.clearButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
File file = null;
int result = 0;
String getaddress = null;
String queryResult = null;
JFileChooser fileChooser = new JFileChooser();
if(e.getSource() == this.exit){
System.exit(1);
}
if(e.getSource() == this.clearButton){
addressText.setText("");
}
if(e.getSource() == this.queryButton){
getaddress = addressText.getText();
File file1 = new File(getaddress);
try {
if(getaddress.startsWith("http")){
queryResult = MailCheck.getWebMail(getaddress).toString();//网络地址
area.setText(queryResult);
}else{
if(file1.exists()){
queryResult = MailCheck.getLocalMail(getaddress).toString();//本地地址
area.setText(queryResult);
}else{
area.setText("不是正确的文件路径");
}
}
// area.setText(queryResult);
// System.out.println(MailCheck.getWebMail(getaddress));
} catch (Exception e1) {
System.out.println("查询出现问题...");;
}
}
if(e.getSource() == this.save){
result = fileChooser.showSaveDialog(this.frame);
if(result ==JFileChooser.APPROVE_OPTION){
file = fileChooser.getSelectedFile();
// this.label.setText("请选择保存文件名:"+file.getName());
}
// else if(result == JFileChooser.CANCEL_OPTION){
// this.label.setText("没有选择文件");
// }else{
// this.label.setText("操作错误");
// }
if(file != null){
try {
PrintStream printStream = new PrintStream(new FileOutputStream(file));
printStream.print(this.area.getText());
printStream.close();
} catch (FileNotFoundException e1) {
this.label.setText("文件保存失败");
}
}
}
}
}
Sky灬云岚
- 粉丝: 105
- 资源: 14
最新资源
- 【java毕业设计】英语学习平台源码(springboot+vue+mysql+说明文档).zip
- 【java毕业设计】考研资讯系统源码(springboot+vue+mysql+说明文档).zip
- 【java毕业设计】考务管理系统的设计与实现源码(springboot+vue+mysql+说明文档).zip
- 气泡排序、插入排序、选择排序、快速排序、希尔排序、堆排序、合并排序-SortAlgorithm.zip
- sso-end-v1dasdaswewqdadsadasasd
- 【java毕业设计】网上商城源码(springboot+vue+mysql+说明文档).zip
- 【java毕业设计】网上书店源码(springboot+vue+mysql+说明文档).zip
- 【java毕业设计】竞赛管理系统源码(springboot+vue+mysql+说明文档).zip
- 【java毕业设计】程序设计基础课程辅助教学系统源码(springboot+vue+mysql+说明文档).zip
- 超详细中文版TA-Lib库使用教程.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈