import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.LinkedList;@SuppressWarnings("serial")public class Chess extends JFrame implements ActionListener{ChessBoard board=null;Demon demon=null;MakeChessManual record=null;Container con=null;JMenuBar bar;JMenu fileMenu;JMenuItem 制作棋谱,保存棋谱,演示棋谱;JFileChooser fileChooser=null;@SuppressWarnings("rawtypes")LinkedList 棋谱=null;public void setTitle(String title) {super.setTitle("中国象棋");}public Chess(){bar=new JMenuBar();fileMenu=new JMenu("中国象棋");制作棋谱=new JMenuItem("制作棋谱");保存棋谱=new JMenuItem("保存棋谱");演示棋谱=new JMenuItem("演示棋谱");fileMenu.add(制作棋谱);fileMenu.add(保存棋谱);fileMenu.add(演示棋谱);bar.add(fileMenu);setJMenuBar(bar);setTitle(制作棋谱.getText());制作棋谱.addActionListener(this);保存棋谱.addActionListener(this);演示棋谱.addActionListener(this);board=new ChessBoard(45,45,9,10);record=board.record;con=getContentPane();JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,board,record);split.setDividerSize(5);split.setDividerLocation(460);con.add(split,BorderLayout.CENTER);addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0);}});setVisible(true);setBounds(60,20,670,540);fileChooser=new JFileChooser();con.validate();validate();}@SuppressWarnings("rawtypes")public void actionPerformed(ActionEvent e){if(e.getSource()==制作棋谱){con.removeAll();// 保存棋谱.setEnabled(true);this.setTitle(制作棋谱.getText());board=new ChessBoard(45,45,9,10);record=board.record;JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,board,record);split.setDividerSize(5);split.setDividerLocation(460);con.add(split,BorderLayout.CENTER);validate();}if(e.getSource()==保存棋谱){int state=fileChooser.showSaveDialog(null);File saveFile =fileChooser.getSelectedFile();if(saveFile!=null&&state==JFileChooser.APPROVE_OPTION){try{FileOutputStream outOne=new FileOutputStream(saveFile);ObjectOutputStream outTwo=new ObjectOutputStream(outOne);outTwo.writeObject(record.getChessManual()) ;outOne.close();outTwo.close();}catch(IOException event){}}}if(e.getSource()==演示棋谱){con.removeAll();con.repaint();con.validate();validate();保存棋谱.setEnabled(false);int state=fileChooser.showOpenDialog(null);File openFile =fileChooser.getSelectedFile();if(openFile!=null&&state==JFileChooser.APPROVE_OPTION){try{FileInputStream inOne=new FileInputStream(openFile);ObjectInputStream inTwo=new ObjectInputStream(inOne);棋谱=(LinkedList)inTwo.readObject() ;inOne.close();inTwo.close();ChessBoard board=new ChessBoard(45,45,9,10);demon=new Demon(board);demon.set棋谱(棋谱);con.add(demon,BorderLayout.CENTER);con.validate();validate();this.setTitle(演示棋谱.getText()+":"+openFile);}catch(Exception event){JLabel label=new JLabel("不是棋谱文件");label.setFont(new Font("隶书",Font.BOLD,60));label.setForeground(Color.red);label.setHorizontalAlignment(SwingConstants.CENTER);con.add(label,BorderLayout.CENTER);con.validate();this.setTitle("没有打开棋谱");validate();}}else{JLabel label=new JLabel("没有打开棋谱文件");label.setFont(new Font("隶书",Font.BOLD,50));label.setForeground(Color.pink);label.setHorizontalAlignment(SwingConstants.CENTER);con.add(label,BorderLayout.CENTER);con.validate();this.setTitle("没有打开棋谱文件");validate();}}}public static void main(String args[]){new Chess();}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。