⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 noticecenter.java

📁 企业内部管理系统
💻 JAVA
字号:
package viewtuba1;

import java.awt.ComponentOrientation;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;

import model.ClockLabel;

public class NoticeCenter extends JFrame {

	private JTextArea textArea_1;

	private JTextArea textArea;

	static NoticeCenter frame;

	/**
	 * Launch the application
	 * 
	 * @param args
	 */
	public static void main(String args[]) {
		try {
			frame = new NoticeCenter();
			frame.setTitle("Notice Center");
			frame.setVisible(true);
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the frame
	 */
	public void SaveNoticeJc() {
		JFileChooser fc = new JFileChooser();
		fc.setCurrentDirectory(new File("d:\\workspace\\Library\\txt"));
		fc.setSelectedFile(new File("outside.txt"));
		int retMethod = fc.showSaveDialog(fc);
		File csvFile = fc.getSelectedFile();
		StringBuffer s = new StringBuffer();
		s.append(textArea.getText());
		if (retMethod == JFileChooser.APPROVE_OPTION) {
			try {
				FileWriter fw = new FileWriter(csvFile);
				fw.write(s.toString());
				fw.flush();
				fw.close();
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}
		}
	}
	public void SaveNoticeJc1() {
		JFileChooser fc = new JFileChooser();
		fc.setCurrentDirectory(new File("txt"));
		fc.setSelectedFile(new File("*.txt"));
		int retMethod = fc.showSaveDialog(fc);
		File csvFile = fc.getSelectedFile();
		StringBuffer s = new StringBuffer();
		s.append(textArea_1.getText());
		if (retMethod == JFileChooser.APPROVE_OPTION) {
			try {
				FileWriter fw = new FileWriter(csvFile);
				fw.write(s.toString());
				fw.flush();
				fw.close();
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}
		}
	}

	public String OpenNoticeJc() {

		JFileChooser fc = new JFileChooser();
		fc.setCurrentDirectory(new File("txt"));
		fc.setSelectedFile(new File(""));
		int retMethod = fc.showOpenDialog(fc);
		File csvFile = fc.getSelectedFile();
		String s1, s2 = null;
		if (retMethod == JFileChooser.APPROVE_OPTION) {
			try {
				BufferedReader br = new BufferedReader(new FileReader(csvFile));
				while ((s1 = br.readLine()) != null)
					s2 += s1 + "\n";
				br.close();
				return s2;
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}
		}
		return null;
	}

	public NoticeCenter() {
		super();
		getContentPane().setLayout(null);
		setBounds(100, 100, 582, 496);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		final JSplitPane splitPane = new JSplitPane();
		splitPane.setResizeWeight(0.5);
		splitPane.setBounds(29, 29, 512, 347);
		getContentPane().add(splitPane);

		final JSplitPane splitPane_1 = new JSplitPane();
		splitPane_1.setResizeWeight(0.9);
		splitPane_1.setOrientation(JSplitPane.VERTICAL_SPLIT);
		splitPane.setLeftComponent(splitPane_1);

		final JPanel panel = new JPanel();
		panel.setLayout(null);
		splitPane_1.setRightComponent(panel);

		Icon icon = new ImageIcon("image/save.gif");
		Icon icon1 = new ImageIcon("image/open.gif");
		final JButton button = new JButton();
		button.setText("打开");
		button.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String s1 = null;
				s1 = OpenNoticeJc();
				textArea.setText(s1);
			}

		});
		button.setIcon(icon1);
		button.setBounds(21, 4, 100, 23);
		panel.add(button);

		final JButton button_1 = new JButton();
		button_1.setText("保存");
		button_1.setIcon(icon);
		button_1.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				SaveNoticeJc();
			}
			
		});
		button_1.setBounds(127, 4, 100, 23);
		panel.add(button_1);

		final JScrollPane scrollPane = new JScrollPane();
		splitPane_1.setLeftComponent(scrollPane);

		textArea = new JTextArea();
		scrollPane.setViewportView(textArea);

		final JSplitPane splitPane_2 = new JSplitPane();
		splitPane_2.setResizeWeight(0.9);
		splitPane_2.setOrientation(JSplitPane.VERTICAL_SPLIT);
		splitPane.setRightComponent(splitPane_2);

		final JPanel panel_1 = new JPanel();
		panel_1.setLayout(null);
		splitPane_2.setRightComponent(panel_1);

		final JButton button_2 = new JButton();
		button_2.setText("打开");
		button_2.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String s2 = null;
				s2 = OpenNoticeJc();
				textArea_1.setText(s2);
			}

		});
		button_2.setIcon(icon1);
		button_2.setBounds(20, 3, 100, 23);
		panel_1.add(button_2);

		final JButton button_1_1 = new JButton();
		button_1_1.setText("保存");
		button_1_1.setIcon(icon);
		button_1_1.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				SaveNoticeJc1();
			}
			
		});
		button_1_1.setBounds(126, 3, 100, 23);
		panel_1.add(button_1_1);

		final JScrollPane scrollPane_1 = new JScrollPane();
		splitPane_2.setLeftComponent(scrollPane_1);

		textArea_1 = new JTextArea();
		scrollPane_1.setViewportView(textArea_1);

		final JLabel label = new JLabel();
		label.setText("登陆界面信息管理");
		label.setBounds(99, 2, 112, 23);
		getContentPane().add(label);

		final JLabel label_1 = new JLabel();
		label_1.setText("内部信息发布管理");
		label_1.setBounds(358, 2, 121, 23);
		getContentPane().add(label_1);

		final JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		final JMenuItem menuItem = new JMenuItem();
		menuItem.setText("退出");
		menuItem.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				dispose();
			}

		});
		menuBar.add(menuItem);

		final JLabel label_2 = new JLabel();
		label_2.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		label_2.setText("系统时间:");
		label_2.setBounds(407, 399, 72, 23);
		getContentPane().add(label_2);

		final JLabel label_2_1 = new ClockLabel();
		label_2_1.setBounds(484, 399, 65, 23);

		getContentPane().add(label_2_1);
		//
	}

	public static NoticeCenter getFrame() {
		return frame;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -