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

📄 designframe.java

📁 一个简单的考试系统录入程序
💻 JAVA
字号:
package exam;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;


class DesignFrame extends JFrame implements ActionListener, ListSelectionListener
{
	private JMenuBar menubar;
	private JMenu menu1, menu2, menu3,menu4,menu5;
	private JMenuItem item1, item2, item3, item4, item5, item6;
	private JMenuItem item7, item8, item9, item10, item11, item12;
	private String string1[]= {"课程选项", "高等数学","操作系统", "数据结构","数据库原理"};
	private String string2[] = {"章节选项", "第一章","第二章","第三章", "第四章"};
	private String string3[] = {"题型选项", "填空","判断", "多项选择","问答","计算"};
	private String string4[] = {"题型难度","难", "中", "易"};
	private String string5[] = {"=", "<", ">", "<=", ">=", "%", "&","※","x",
	                            "$", "#", "@","¥","㎡","【", "】","﹌","⊕",
	                            "∫","≠","∏","∈","∪","∩","≌","∞" };
	private JComboBox comboBox1, comboBox2, comboBox3, comboBox4;
	private JButton button1, button2;
	private JTextField textField1, textField2;
	private JLabel label1, label2;
	private JScrollBar scrollbar1;
	private int selectedIndex1, selectedIndex2, selectedIndex3, selectedIndex4;
	private JScrollPane scroller1, scroller2;
	private JTextArea textArea1, textArea2;
	private String input, input1, input2;
	private JList list;
    private Container c;
    
/************************* GUI**********************/	
		public DesignFrame()
	{
	  super("添加题库");
	
	//  setSize(700, 500);
	  setBackground(Color.blue);
	   c = getContentPane();
	  
	  JPanel northPanel = new JPanel();
	  northPanel.setLayout(new GridLayout(1,5));
	  setJMenuBar(menubar);  
	  menubar = new JMenuBar();
	  
	  menu1 = new JMenu(" 文件 ");
	  menu2 = new JMenu(" 编辑 ");
	  menu3 = new JMenu(" 格式 ");
	  menu4 = new JMenu(" 插入 ");
	  menu5 = new JMenu(" 帮助 ");
	  
	  item1 = new JMenuItem("打开");
	  item2 = new JMenuItem("保存");
	  item3 = new JMenuItem("打印");
	  
	  item4 = new JMenuItem("复制");
	  item5 = new JMenuItem("全选");
	  item6 = new JMenuItem("粘贴");
	  
	  item7 = new JMenuItem("大小");
	  item8 = new JMenuItem("字体");
	  item9 = new JMenuItem("斜体");
	  
	  item10 = new JMenuItem("图片");
	  
	  item11 = new JMenuItem("目录");
	  item12 = new JMenuItem("索引");
	 
	  menu1.add(item1);
	  menu1.add(item2);
	  menu1.add(item3);
	    
	  menu2.add(item4);
	  menu2.add(item5);
	  menu2.add(item6);
	  
	  menu3.add(item7);
	  menu3.add(item8);
	  menu3.add(item9);
	  
	  menu4.add(item10);
	  
	  menu5.add(item11);
	  menu5.add(item12);
	  
	  menubar.add(menu1);
	  menubar.add(menu2);
	  menubar.add(menu3);
	  menubar.add(menu4);
	  menubar.add(menu5);
	  northPanel.add(menubar);
	  
	  JPanel centralPanel = new JPanel();
	  centralPanel.setLayout(new GridLayout());
	  comboBox1 = new JComboBox(string1);
	  comboBox1.addItemListener(new ItemListener(){
	  	public void itemStateChanged(ItemEvent e)
	  	   {
	  	   	 selectedIndex1 = comboBox1.getSelectedIndex();
	  	      }
	    	}
	     );	
	     
	  comboBox2 = new JComboBox(string2);
	  comboBox2.addItemListener(new ItemListener(){
	  	public void itemStateChanged(ItemEvent e)
	  	   {
	  	   	 selectedIndex2 = comboBox2.getSelectedIndex();
	  	      }
	    	}
	     );	
	     
	  comboBox3 = new JComboBox(string3);
	  comboBox3.addItemListener(new ItemListener(){
	  	public void itemStateChanged(ItemEvent e)
	  	   {
	  	   	 selectedIndex3 = comboBox3.getSelectedIndex();
	  	      }
	    	}
	     );	 
	   
	  comboBox4 = new JComboBox(string4);
	  comboBox4.addItemListener(new ItemListener(){
	  	public void itemStateChanged(ItemEvent e)
	  	   {
	  	   	 selectedIndex4 = comboBox4.getSelectedIndex();
	  	      }
	    	}
	     );	 
	     
	   label1 = new JLabel(" 分数 ");  
	   label2 = new JLabel(" 难度 ");
	   textField1 = new JTextField();
	   textField1.addActionListener(this);
	   //textField2 = new JTextField();
	
	   button1 = new JButton("提交");
	   button1.addActionListener(this);
       
	   centralPanel.add(comboBox1);
	   centralPanel.add(comboBox2);
	   centralPanel.add(comboBox3);
	   centralPanel.add(label1);
	   centralPanel.add(textField1); 
	   //centralPanel.add(label2);
	   centralPanel.add(comboBox4);
	   centralPanel.add(button1);
	   
	   JPanel southPanel = new JPanel();
	   JPanel south_sub1 = new JPanel();
	   JPanel south_sub2 = new JPanel();
	   southPanel.setLayout(new BorderLayout());
	   south_sub2.setLayout(new BorderLayout());
	   
	   textArea1 = new JTextArea(22, 52);    
	   scroller1 = new JScrollPane(textArea1);
	   south_sub1.add(scroller1, BorderLayout.WEST);
	   
	   //southPanel.add(scroller); //ok 
	   button2 = new JButton("数学符号    ");
	   south_sub2.add(button2, BorderLayout.NORTH);
	   
	   list = new JList(string5);
	   list.addListSelectionListener(this);
	   list.setVisibleRowCount(19);
	   list.setFixedCellHeight(20);
	   //list.setSelectionMode(
         // ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
        
	   scroller2 = new JScrollPane(list);
	   south_sub2.add(scroller2, BorderLayout.SOUTH);
	   
	 
       southPanel.add(south_sub1, BorderLayout.WEST);
	   southPanel.add(south_sub2, BorderLayout.EAST);
	  
	   c.setLayout(new BorderLayout());
	   c.add(northPanel, BorderLayout.NORTH);
	   c.add(centralPanel, BorderLayout.CENTER);
 	   c.add(southPanel, BorderLayout.SOUTH);
	  
	  // show();
	  
	 }  // end constructor
	 

	 // submit question
	public void actionPerformed(ActionEvent e)
	{
	  Object source = e.getSource();
	  if(source == button1)
	   {
	      //input = textArea1.getText();
	      if((textArea1.getText()).length()<1)
	        {
	        	JOptionPane.showMessageDialog(null, 
	        	  "      请输入试题!!!", "提醒", 
	        	  JOptionPane.INFORMATION_MESSAGE);
	        	  return;
	        	  
	             	  } //end if
	             	  
	            //textArea1.setText(" ");
		          
    	} // end if
    
       if(source == button1)
	   {	
	      //input1 = textField1.getText();
	      if((textField1.getText()).length()<1)
	        {   	
	        	JOptionPane.showMessageDialog(null, 
	        	  "     请输入分数!!!", "提醒", 
	        	  JOptionPane.INFORMATION_MESSAGE);
	        	  return;
	            
	             	  } //end if
	           
        	} // end if
    	
    	
    	if((textField1.getText())!=null && (textArea1.getText())!=null)
    	
    		{
    			String send_cont = ("*1")+ comboBox1.getSelectedItem()+
    		                       ("*2")+ comboBox2.getSelectedItem()+
    		                       ("*3")+ comboBox3.getSelectedItem()+
    		                       ("*4")+ textArea1.getText()+
    		                       ("*5")+ textField1.getText()+
    		                       ("*6")+ comboBox4.getSelectedItem();
    		                    
    		        System.out.println(send_cont);  
    		        textArea1.setText("");
    		        
    		        //Design_Rec.question_send(send_con);
    		                
    		        } //end if
   
           } // end actionPerformed 
         
   public void valueChanged(ListSelectionEvent le)
    {
    	if(le.getValueIsAdjusting()){
    	  return;}
    	  
    	  int[] index = list.getSelectedIndices();
    	  for (int i=0; i<index.length; i++){
    	  String s = (String) list.getModel().getElementAt(index[i]);	
    	  textArea1.append(s);
             }
    	
    	} //end valueChanged    
  }

⌨️ 快捷键说明

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