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

📄 mainframe.java

📁 一款背单词的小程序,可以自己在自定义词库中加单词,运行环境JCreator
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MainFrame extends JFrame
{
	JPanel panel1 = new JPanel();
	JPanel panel2 = new JPanel();
	JPanel panel3 = new JPanel();
	MyPanel backJpanel = new  MyPanel("image\\blue.jpg");
    //JLabel backJpanel = new JLabel();
    static	JTextArea displayText1 = new JTextArea(3,30);
	static  JTextArea displayText2 = new JTextArea(3,30);
	JPanel labelPanel = new JPanel();
	JLabel label = new JLabel("剩余单词数:");
    static JLabel displayLabel = new JLabel(String.valueOf(ReadDat.wordCount));
	JButton  frontButton = new JButton();
	JButton  nextButton = new JButton();
	JButton  pauseButton = new JButton();
	JButton  autoButton = new JButton();
	JButton  setButton = new JButton("设置");
	JButton  searchButton = new JButton("查找");
	JButton  testButton = new JButton("测试");
	JButton  exitButton = new JButton("退出");
	JPanel pan1= new JPanel();
	JPanel pan2= new JPanel();
     static JCheckBox checkBox1 = new JCheckBox("不显示中文");
	 static JCheckBox checkBox2 = new JCheckBox("不显示英文");
	 ButtonListener bl = new ButtonListener();
	 ImageIcon  image ;
	 static WordThread wordThread;
	 
//////////////////////////////////////////////////////////////
//////////////	
	MainFrame()
	{
	  
		wordThread = new WordThread();
	 
		WindowListen wl = new WindowListen();
    	CheckBoxListener boxl =new CheckBoxListener();
		checkBox1.addActionListener(boxl);
		checkBox2.addActionListener(boxl);
		displayText1.setEditable(false);
		displayText2.setEditable(false);
		Container con = this.getContentPane();
		
		GridLayout gl = new GridLayout(2,1);
		labelPanel.setLayout(gl);
		labelPanel.add(label);
		labelPanel.add(displayLabel);
	    labelPanel.setOpaque(false);
		gl = new GridLayout(3,1);
		//panel1.add(new JPanel());
		panel1.setLayout(gl);
		//gl.setVgap(25);
		panel1.add(displayText1);
	
		panel1.add(displayText2);
		panel2.add(labelPanel);
		panel2.add(frontButton);
		panel2.add(nextButton);
		panel2.add(pauseButton);
		panel2.add(autoButton);
		panel1.add(pan1);
		pan1.setOpaque(false);
		pan2.setOpaque(false);
		pan1.setLayout(new BorderLayout());
        pan2.setPreferredSize(new Dimension(20,25));
		pan1.add(pan2,BorderLayout.NORTH);
		pan1.add(panel2);
		
		gl = new GridLayout(6,1);
		panel3.setLayout(gl);
		gl.setVgap(15);
		panel3.add(checkBox1);
		panel3.add(checkBox2);
		panel3.add(setButton);
		panel3.add(testButton);
		panel3.add(searchButton);
		panel3.add(exitButton);
		//con.setLayout(new FlowLayout());
		backJpanel.setLayout(new FlowLayout());
		backJpanel.add(panel1);
		backJpanel.add(panel3);
		//backJpanel.add(new JButton("11111"));
		
		con.add(backJpanel);
	    
        panel1.setOpaque(false);
        panel2.setOpaque(false);
        panel3.setOpaque(false);
		checkBox1.setOpaque(false);
		checkBox2.setOpaque(false);
		setButton.setOpaque(false);
		exitButton.setOpaque(false);
		image = new ImageIcon("image\\left.jpg");
		frontButton.setIcon(image);
		image = new ImageIcon("image\\right.jpg");
		nextButton.setIcon(image);
		image = new ImageIcon("image\\stop.jpg");
		pauseButton.setIcon(image);
		image = new ImageIcon("image\\start.jpg");
		autoButton.setIcon(image);
		frontButton.setBackground(Color.white);
        autoButton.setBackground(Color.white);	
        pauseButton.setBackground(Color.white);
        nextButton.setBackground(Color.white);
        setButton.setForeground(Color.yellow);
        searchButton.setForeground(Color.yellow);
        searchButton.setOpaque(false);
        searchButton.setFont(new Font("宋体",Font.BOLD,15));
        setButton.setFont(new Font("宋体",Font.BOLD,15));
        testButton.setFont(new Font("宋体",Font.BOLD,15));
        testButton.setForeground(Color.yellow);
        testButton.setOpaque(false);
        exitButton.setForeground(Color.yellow);
        exitButton.setFont(new Font("宋体",Font.BOLD,15));
        checkBox1.setForeground(Color.yellow);
        checkBox1.setFont(new Font("宋体",Font.BOLD,15));
        checkBox2.setForeground(Color.yellow);
        checkBox1.setForeground(Color.yellow);
        label.setForeground(Color.yellow);
        displayText1.setForeground(Color.blue);
        displayText2.setForeground(Color.blue);
        displayText1.setFont(new Font("宋体",Font.BOLD,20));
        displayText2.setFont(new Font("宋体",Font.BOLD,20));
        displayLabel.setForeground(Color.yellow);
        checkBox2.setFont(new Font("宋体",Font.BOLD,15));
        label.setFont(new Font("宋体",Font.BOLD,15));
        displayLabel.setFont(new Font("宋体",Font.BOLD,15));
      this.setResizable(false);	
      pauseButton.addActionListener(bl);
      autoButton.addActionListener(bl);	 
      frontButton.addActionListener(bl);
      nextButton.addActionListener(bl);
      exitButton.addActionListener(bl);
      setButton.addActionListener(bl);
      searchButton.addActionListener(bl);
      testButton.addActionListener(bl);
	  this.addWindowStateListener(wl);
	  
//	  this.addMouseListener(WordFrame.ml);
	 
	  this.setSize(550,300);
	  this.setVisible(true);
	  wordThread.start();
	   wordThread.suspend();	
	}
	
static 	public void pauseThread()
	{
		wordThread.suspend();
	}
	
	//////////////////////////////////////////////
	////////////
static	 public void startThread()
	{
		wordThread.resume();
	}
	///////////////////////////////////////////
	///////////
	
 
}
class ButtonListener implements ActionListener
 {
	int delay ;
	boolean rbf1 =false;
	boolean rbf2 =false;
	boolean rbf3 =false;
	boolean cb1 =false;
	boolean cb2 =false; 
	int order = 1;
	
	public void actionPerformed(ActionEvent e)
	{
	   if(e.getSource() == pauseButton)
	    {
	    	try{
	    	
         	     wordThread.suspend();
	           }
	          catch(Exception ee)
	          {
	          	System.out.println("线程暂停错误" + ee.getMessage());
	          }
	    
	    }
	    //////////////////////////////////////////////////////////////////
	    if(e.getSource() == searchButton)
	    {
	    	Search search = new Search(ReadDat.filePath+ReadDat.fileName);
	    
	    }
	    
	    ///////////////////////////////////////////////////////
	    //////////////
	    if(e.getSource() == autoButton)
	    {
	    	
	    	wordThread.resume();
	    	System.out.println("线程暂停错误" );
	    }
	    ////////////////////////////////////////////////////////////
	    ////////////////
	    if(e.getSource() == setButton)
	    {
	       WordSetFrame frame = new WordSetFrame();
	       // Word.wordSetFrame.getValue();
	       wordThread.suspend();
	    	
		   
	    	//Word.wordSetFrame.wordStorePanel.setModel();
	    	//ord.wordSetFrame.setVisible(true);
	    	
	    }
	    ////////////////////////////////////////////////////////////////
	    ////////////////////
	    if(e.getSource()==exitButton)
	    {
	    	System.exit(0);
	    }
	    ///////////////////////////////////////////////////////////////
	    if(e.getSource()==testButton)
	    {
	    	TestWord testWord = new TestWord(ReadDat.englishMean,ReadDat.chineseMean);
	    }
	    ///////////////////////////////////////////////////////////
	    ///////////////////////
	    if(e.getSource()==frontButton)
	    {
	       wordThread.frontWord();
			
	    }
	    //////////////////////////////////////////////
	    //////////////
	    if(e.getSource() == nextButton)
	    {
	  
	      wordThread.nextWord();		
			
	    }
	    
	    
	 
  }	
	
 }
class WindowListen extends WindowAdapter
{
	WordFrame wordFrame =new WordFrame();
	boolean flag = false;
	public void windowStateChanged(WindowEvent e) 
    {
    	
    	if(flag)
    	 flag = false;
    	 else
    	 flag =true;
    	wordFrame.setVisible(flag);
    	wordFrame.toFront();
    	System.out.println("zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz");
    }
}

⌨️ 快捷键说明

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