In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use Java to create a simple English learning system". In the operation of practical cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
[1. Project background]
With the development of mobile Internet, English learning system can organize large amounts of data in a structured way. According to the individual needs of users, it is presented to users in a targeted way, so as to provide convenience for English learners and improve their learning efficiency.
[II. Project objectives]
1. Achieve a beautiful interface and add the required components.
two。 Can basically change the font, color, background, page switching function.
3. Java reads the txt file to simplify the code.
[III. Project implementation]
Using eclipse software development, first put up the effect picture, as shown in the following figure. You can see that there is a menu bar on the interface that can change fonts, colors, set options, and the function of page switching.
Next, the editor will take you to carry out the specific implementation, and the specific implementation steps are as follows.
[IV. Implementation steps]
First, implement the form interface first.
The specific code implementation process is as follows:
Public static void main (String [] args) {/ / TODO Auto-generated method stub EnglishSystem es = new EnglishSystem (); es.setTitle (English Learning system); es.setSize (750,600); es.setVisible (true); es.setResizable (false); es.setLocationRelativeTo (null);}
Create an EnglishSystem class using the new keyword
SetTitle indicates the title of the settings interface
SetSize (width, height) represents the size of the form
SetVisible (true or false) indicates whether the form is visible or not
SetResizable (true or false) indicates whether the form can be resized by the user
SetLocationRelativeTo () indicates the position of the setting window relative to the specified component.
Second, realize the menu bar
1. Create a JFrame instance, a JPanel panel, and then add the panel to the JFrame.
two。 Create JMenuBar menu bar objects, and JMenu is creating menu objects, adding menu objects to menu bar objects.
3. Add JMenuItem menu items to JMenu.
Public class EnglishSystem extends JFrame {private JPanel panel01 = new JPanel (); / / menu bar private JMenuBar jb = new JMenuBar (); private JMenu menu01 = new JMenu ("font"); private JMenuItem item01 = new JMenuItem ("boldface"); private JMenuItem item02 = new JMenuItem ("bold"); private JMenu menu02 = new JMenu ("color"); private JMenuItem item03 = new JMenuItem ("rose red"); private JMenuItem item04 = new JMenuItem ("blue"); private JMenuItem item05 = new JMenuItem ("green") Private JMenuItem item06 = new JMenuItem ("orange"); private JMenuItem item07 = new JMenuItem ("black"); private JMenu menu03 = new JMenu ("setup"); private JMenuItem item08 = new JMenuItem ("change wallpaper"); private JMenuItem item09 = new JMenuItem ("exit")
4. Realize the word area
Private JPanel panel03 = new JPanel (); / / the word shows private static JTextArea text01 = new JTextArea (302.89)
5. Realize the switch between upper and lower pages
Private JPanel panel04 = new JPanel (); private JButton btn_next = new JButton ("next page"); private JButton btn_last = new JButton ("previous page")
6. Picture of the current background
Number of private int photoNum=1;// background images private JPanel imagePanel; private ImageIcon bg= new ImageIcon ("photo//photo" + photoNum+ ".png"); / / background images private JLabel label = new JLabel (bg)
7. EnglishSystem class constructor: the main purpose of constructing this function is to implement the interface design and add components.
EnglishSystem () {jb.add (menu01); jb.add (menu02); jb.add (menu03); menu01.add (item01); menu01.add (item02); menu02.add (item03); menu02.add (item04); menu02.add (item05); menu02.add (item06); menu02.add (item07); menu03.add (item08); menu03.add (item09); panel01.add (jb) This.add (panel01); this.setJMenuBar (jb); panel03.add (text01); text01.setText (str1); text01.setEditable (false); text01.setLineWrap (true); text01.setWrapStyleWord (true); panel03.setBorder (new TitledBorder (word area)); this.add (panel03,BorderLayout.CENTER); text01.setFont (new Font (boldface, Font.PLAIN,14))
8. Add font, color, background to the JMenuBar menu bar, and menu items in the font, such as boldface and Arial, to the menu. The same is true for other color and background add components!
Panel04.add (btn_last); panel04.add (btn_next); this.add (panel04,BorderLayout.SOUTH); text01.setOpaque (false); panel01.setOpaque (false); panel03.setOpaque (false); panel04.setOpaque (false); label.setBounds / / get the content panel of the form imagePanel.setOpaque (false); / / set transparent this.getLayeredPane () .add (label,new Integer (Integer.MIN_VALUE))
9. Define event handling classes and implement event listeners
Private MyListener my = new MyListener ()
10. Add listeners to the specified component in the EnglishSystem constructor
Item01.addActionListener (my); item02.addActionListener (my); item03.addActionListener (my); item04.addActionListener (my); item05.addActionListener (my); item06.addActionListener (my); item07.addActionListener (my); item08.addActionListener (my); item09.addActionListener (my); btn_next.addActionListener (my); btn_last.addActionListener (my)
11. Add the event listener MyListener (name it yourself).
Private class MyListener implements ActionListener {@ Override public void actionPerformed (ActionEvent e) {/ / TODO Auto-generated method stub if (e.getSource () = = item01) {/ / Arial text01.setFont (new Font ("Arial", Font.PLAIN,14));} if (e.getSource () = = item02) {/ / boldface text01.setFont (new Font ("boldface", Font.PLAIN,14)) } if (e.getSource () = = item03) {/ / Rose text01.setForeground (new Color (255heli0255));} if (e.getSource () = = item04) {/ / Blue text01.setForeground (Color.blue);} if (e.getSource () = = item05) {/ / Green text01.setForeground (new Color } if (e.getSource () = = item06) {/ / Orange text01.setForeground (new Color (255 140Power0));} if (e.getSource () = = item07) {/ / Black text01.setForeground (Color.BLACK);} if (e.getSource () = = item08) {/ / change wallpaper photoNum++; if (photoNum > = 6) {photoNum=1 } label.setIcon (new ImageIcon ("photo//photo" + photoNum+ ".png"));} if (e.getSource () = = item09) {/ / exit dispose ();} if (e.getSource () = = btn_next) {/ / next page if (papeNum1) {/ / not the first page papeNum--; btn_last.setEnabled (true); btn_next.setEnabled (true);} if (papeNum==1) {btn_last.setEnabled (false); btn_next.setEnabled (true);}}
twelve。 The display text in the program is stored in the form of String array, which is easy to understand, but it makes more code. Therefore, in the case of more text, you should consider storing the story text in the form of an txt document and reading the document content in the program to display it in the window.
Read the Txt file:
File file = new File (s [papeNum-1]); String str1 = getFileContent (file); text01.setText (str1)
13. Define an array of strings
Private String [] s = new String [] {"resource//s01.txt", "resource//s02.txt", "resource//s0 3.txt", "resource//s04.txt", "resource//s05.txt", "resource//s06. Txt "," resource//s07.txt "," resource//s08.txt "," resource//s09.tx t "," resource//s10.txt "," resource//s11.txt "," resource//s12.txt "," resource//s13.txt "," resource//s14.txt "}; private int papeNum=1;// pages
14. Get the file contents in the getFileContent function
Private String getFileContent (File file) {/ / get file contents BufferedReader br = null; StringBuffer sb = new StringBuffer (); try {br = new BufferedReader (new FileReader (file)); String hasRead = null; while ((hasRead = br.readLine ())! = null) {sb.append (hasRead + "\ n") } catch (Exception e) {} finally {if (br! = null) {try {br.close ();} catch (IOException e) {} return sb.toString ();}
The components used above are mainly Java Swing graphical interface development:
1. Swing is part of the base class of JAVA.
2. Swing includes graphical user interface (GUI) devices such as text boxes, buttons, separation panes and tables.
3. Swing provides many better on-screen display elements than AWT, which is implemented in pure Java and is more compatible with cross-platform operation.
This is the end of the introduction of "how to use Java to create a simple English learning system". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 266
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.