package ChapterPak;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.event.*;
import *;
public class MainFrame extends JFrame{
JTabbedPane tabbedPane = new JTabbedPane();
JTextArea textAreal = new JTextArea();
JScrollPane scrollPane = new JScrollPane(textAreal,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
JPanel panel= new JPanel();
JMenuBar menuBar;
JMenu menu;
JMenuItem menuItem;
Login login;
public MainFrame(Login ll)
{
this.login = ll;
this.setTitle("标签面板显示");
menuBar = new JMenuBar();
this.setJMenuBar(menuBar);
menu = new JMenu("文件");
menuBar.add(menu);
menuItem = new JMenuItem("打开");
menuItem.addActionListener(new ActionHandler_1(this));
menu.add(menuItem);
menuItem = new JMenuItem("新建");
menu.add(menuItem);
menuItem = new JMenuItem("退出");
menuItem.addActionListener(new ActionHandler_1(this));
menu.add(menuItem);
menu = new JMenu("帮助");
menuBar.add(menu);
menuItem = new JMenuItem("关于");
menu.add(menuItem);
menuItem = new JMenuItem("说明");
menu.add(menuItem);
tabbedPane.addTab("第一页",null,scrollPane,"这是第一页");
tabbedPane.addTab("第二页",null,panel,"这是第二页");
this.getContentPane().add(tabbedPane);
this.setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);
this.addWindowListener(new WindowHandler(this));
this.setSize(800,800);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public void WindowClosing(WindowEvent e)
{
int rr = JOptionPane.showConfirmDialog(null,"你真的要退出吗??","确认框",JOptionPane.YES_NO_OPTION);
if( rr == JOptionPane.YES_OPTION)
{
login.text_1.setText("");
login.passwordField.setText("");
this.hide();
login.loginFrame.show();
}
}
public void actionHandler(ActionEvent e)
{
StringBuffer stringBuffer = new StringBuffer();
if(e.getActionCommand().equals("打开"))
{
JFileChooser fileChoose = new JFileChooser();
int rt = fileChoose.showOpenDialog(null);
if(rt == JFileChooser.APPROVE_OPTION)
{
FileReader fileReader;
try{
File f = fileChoose.getSelectedFile();
fileReader = new FileReader(f);
int c;
c = fileReader.read();
while(c != -1)
{
stringBuffer.append(String.valueOf(c));
c = fileReader.read();
}
textAreal.setText("stringBuffer");
}
catch(Exception e1)
{
JOptionPane.showMessageDialog(null,"没有找到文件");
}
System.out.println(stringBuffer);
// fileReader.close();
}
}
else if(e.getActionCommand().equals("退出"))
{
int rr = JOptionPane.showConfirmDialog(null,"你真的要退出麻??",
"确认框",JOptionPane.YES_NO_OPTION);
if(rr == JOptionPane.YES_OPTION)
{
login.text_1.setText("");
login.passwordField.setText("");
this.hide();
login.loginFrame.show();
}
}
}
}
class WindowHandler extends WindowAdapter
{
MainFrame mf;
public WindowHandler(MainFrame mf)
{
this.mf = mf;
}
public void windowClosing(WindowEvent e)
{
mf.WindowClosing(e);
}
}
class ActionHandler_1 implements ActionListener
{
MainFrame m;
public ActionHandler_1(MainFrame m)
{
this.m = m;
}
public void actionPerformed(ActionEvent e)
{
m.actionHandler(e);
}
}