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

📄 stationmanagerpanel.java

📁 一个可以存储和打印成绩单的系统
💻 JAVA
字号:
package org.signsmile.view;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import org.minjey.cjsjk.core.ModelManager;
import org.minjey.cjsjk.model.Station;

public class StationManagerPanel extends JPanel implements ActionListener {
	private static final long serialVersionUID = 1L;
	private ModelManager modelManager;
	JTextField jtaName, jtaAddress, jtaResponsible, jtaPostmail, jtaContact;
	JTextArea jtaRemark;
	JButton jbtCancel, jbtUpdate, jbtSubmit;
	Station station;
	public StationManagerPanel() {
		createView();
		setEditable(true);
		station = new Station();
		modelManager = MainFrame.getModelManager();
	}
	
	public StationManagerPanel(Station stat) {
		createView();
		setEditable(false);
		this.station = stat;
		showData();
	}
	
	private void assembleStation(){
		if("".equals(jtaName.getText()) || jtaName.getText() == null ){
			JOptionPane.showMessageDialog(null, "请输入函授站名称!");
			return;
		}
//		else if("".equals(jtaResponsible.getText()) || jtaResponsible.getText() == null ){
//			JOptionPane.showMessageDialog(null, "请输入函授站管理员姓名!");
//		}else if("".equals(jtaAddress.getText()) || jtaAddress.getText() == null ){
//			JOptionPane.showMessageDialog(null, "请输入函授站地址!");
//		}else if("".equals(jtaPostmail.getText()) || jtaPostmail.getText() == null ){
//			JOptionPane.showMessageDialog(null, "请输入函授站邮编!");
//		}else if("".equals(jtaContact.getText()) || jtaContact.getText() == null ){
//			JOptionPane.showMessageDialog(null, "请输入函授站联系方式!");
//		}
	
		station.setName(jtaName.getText());
		station.setSadmin(jtaResponsible.getText());
		station.setAddress(jtaAddress.getText());
		station.setPostcode(jtaPostmail.getText());
		station.setTelephone(jtaContact.getText());
		station.setBz(jtaRemark.getText());
	}
	
	private void showData() {
		if(this.station != null){
			jtaName.setText(station.getName());
			jtaResponsible.setText(station.getSadmin());
			jtaAddress.setText(station.getAddress());
			jtaPostmail.setText(station.getPostcode());
			jtaContact.setText(station.getTelephone());
			jtaRemark.setText(station.getBz());
		}		
	}

	private void saveData() {
		assembleStation();
		//station对象直接拿去储存
		setEditable(false);
		modelManager.save(station);
	}
	
	public void createView() {
		JPanel jpLeftFirst = new JPanel();
		jpLeftFirst.setLayout(new GridLayout(5, 1));
		JPanel jpRightFirst = new JPanel();
		jpRightFirst.setLayout(new GridLayout(5, 1));

		JLabel jlName = new JLabel("名称:");
		jlName.setHorizontalAlignment(SwingConstants.RIGHT);
		jpLeftFirst.add(jlName);
		jpRightFirst.add(jtaName = new JTextField(20));

		JLabel jlResponsible = new JLabel("负责人:");
		jlResponsible.setHorizontalAlignment(SwingConstants.RIGHT);
		jpLeftFirst.add(jlResponsible);
		jpRightFirst.add(jtaResponsible = new JTextField(20));

		JLabel jlAddress = new JLabel("地址:");
		jlAddress.setHorizontalAlignment(SwingConstants.RIGHT);
		jpLeftFirst.add(jlAddress);
		jpRightFirst.add(jtaAddress = new JTextField(20));

		JLabel jlPostmail = new JLabel("邮编:");
		jlPostmail.setHorizontalAlignment(SwingConstants.RIGHT);
		jpLeftFirst.add(jlPostmail);
		jpRightFirst.add(jtaPostmail = new JTextField(20));

		JLabel jlContact = new JLabel("联系方式:");
		jlContact.setHorizontalAlignment(SwingConstants.RIGHT);
		jpLeftFirst.add(jlContact);
		jpRightFirst.add(jtaContact = new JTextField(20));

		JPanel jpLeft = new JPanel();
		jpLeft.setLayout(new GridLayout(4, 1));

		JPanel jpRight = new JPanel();
		jpRight.setLayout(new GridLayout(4, 1));
		
		jpLeft.add(jpLeftFirst);
		jpRight.add(jpRightFirst);
		
		JLabel jlRemark = new JLabel("备注:");
		jlRemark.setHorizontalAlignment(SwingConstants.RIGHT);
		jpLeft.add(jlRemark);
		jpRight.add(jtaRemark= new JTextArea(), BorderLayout.CENTER);
		jtaRemark.setBorder(jtaName.getBorder());
		
		JPanel jpButton = new JPanel();
		jpButton.add(jbtUpdate = new JButton("修改"));
		jpButton.add(jbtCancel = new JButton("取消"));
		jpButton.add(jbtSubmit = new JButton("确定"));

		JPanel jpCenter = new JPanel();
		jpCenter.setLayout(new BorderLayout());
		jpCenter.add(jpLeft, BorderLayout.WEST);
		jpCenter.add(jpRight, BorderLayout.CENTER);
		
		this.setLayout(new BorderLayout());
		this.add(jpCenter, BorderLayout.CENTER);
		this.add(jpButton, BorderLayout.SOUTH);
		
		jbtUpdate.addActionListener(this);
		jbtCancel.addActionListener(this);
		jbtSubmit.addActionListener(this);
	}

	public void setEditable(boolean bool){
		jtaName.setEditable(bool);
		jtaResponsible.setEditable(bool);
		jtaAddress.setEditable(bool);
		jtaPostmail.setEditable(bool);
		jtaContact.setEditable(bool);
		jtaRemark.setEditable(bool);
		jtaRemark.setBackground(jtaName.getBackground());
	}

	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == jbtUpdate){
			setEditable(true);
		}else if(e.getSource() == jbtCancel){
			WelcomePanel welcomePanel = new WelcomePanel();
			MainFrame.GetMainFrame().switchView(welcomePanel);
		}else if(e.getSource() == jbtSubmit){
			saveData();
		}
	}

}

⌨️ 快捷键说明

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