eclipse font size setting:Teach you to create a simple storybook with Java (Part 1)-Font Tutorial免费ppt模版下载-道格办公

Teach you to create a simple storybook with Java (Part 1)

To create a simple storybook program in Java, we can use the JavaFX library to achieve a beautiful interface. Here are some basic steps: 1. Set up the project environment: - Install the Java Development Kit (JDK): Make sure the appropriate JDK version is

1. Project Background

With the development of the mobile Internet, electronic books have become the mainstream. According to the needs of users, they are presented to users in a targeted manner, and reading electronic books can improve their learning efficiency.


2. Project goals

1. Achieve a beautiful interface.

2. Can basically Realize the selection of changing font size, font, font style, color, wallpaper, etc., and the button page switching function.

3.java read Take the txt file and simplify the code.


3. Project implementation

Use eclipse software to develop, first upload the rendering, as shown in the figure below. You can see that there is a menu bar on the interface where you can change the font size, font, font style, color, setting options, and page switching functions.

Next, little We will carry out the specific implementation, and the specific implementation steps are as follows.

( 1) First implement the form interface

public static void main(String[] args)throws IOException {// TODO Auto-generated method stub StoryBook s = new StoryBook(); s.setTitle("Small story, big truth"); s.setSize (600,500); s.setVisible(true);}

1. Use the new keyword to create the StoryBook class

setTitle indicates the title of the setting interface; setSize(width, height) indicates the size of the form; setVisible(true or false) indicates whether the form is visible;

The effect picture is as follows:< /span>

( 2) Realize the menu bar

1. Implement menu Column step:

(1) Create JFrame instance, JPanel panel, and then add the panel to the JFrame.

(2) Create JMenuBar menu bar object, JMenu is creating a menu object, and adding the menu object to the menu bar object.

(3) will The JMenuItem menu item is added to the JMenu.

public class StoryBook extends JFrame {//member variable private static JTextArea text01 = new JTextArea("");private String style="宋体";private int pattern = Font.PLAIN;//font (regular) private int size=10;//font size private static String[] str=new String[3];

(4) Panel 1 realizes the layout of the up and down buttons

private JPanel panel01=new JPanel();private JPanel panel02=new JPanel();private JButton btn_last=new JButton("Previous page");private JButton btn_next=new JButton("Next page" );private int papeNum=1;//Current page number 1 2 3

(5) The font size of the menu bar

private JMenuBar jb = new JMenuBar();private JMenu fontsize = new JMenu("font size");private JMenuItem twelf = new JMenuItem("12");private JMenuItem fiveteen = new JMenuItem("15") ;private JMenuItem eighteen = new JMenuItem("18");private JMenuItem twenty = new JMenuItem("20");

(6) The font of the menu bar

private JMenu font = new JMenu("font");private JMenuItem song = new JMenuItem("宋体");private JMenuItem hei = new JMenuItem("黑体");private JMenuItem kai = new JMenuItem(" italics");

(7) The font style of the menu bar

private JMenu fontstyle = new JMenu("Font");private JMenuItem chang = new JMenuItem("General");private JMenuItem jia = new JMenuItem("Bold");private JMenuItem qing = new JMenuItem( "Tilt");

(8) The color of the menu bar

private JMenu color = new JMenu("color");private JMenuItem red = new JMenuItem("red");private JMenuItem green = new JMenuItem("green");private JMenuItem blue = new JMenuItem(" blue");

(10) Menu bar settings

private JMenu intall = new JMenu("Settings"); private JMenuItem swap = new JMenuItem("Change wallpaper");

< span style="letter-spacing: 1px;">(11) Current background image

private int photoNum=1;//The serial number of the currently displayed background image private JPanel imagePanel;private ImageIcon bg= new ImageIcon("photo//photo"+photoNum+".jpg");//Background image private JLabel label = new JLabel(bg);


( 3) Set the properties of the component in the constructor of the StoryBook class

1. Set the font

text01.setLineWrap(true);//Auto wrap text01.setFont(new Font(style,pattern,size));this.add(text01,BorderLayout.CENTER);

2. Settings The button of the previous page of the current first page cannot be clicked, add the button of the next page to the south direction of the border layout

btn_last.setEnabled(false);btn_next.setEnabled(true);panel01.add(btn_last);panel01.add(btn_next);this.add(panel01,BorderLayout.SOUTH);< /pre>

3 .Add the menu of the menu bar (font size, font, font style, color, settings)

jb.add(fontsize);jb.add(font);jb.add(fontstyle);jb.add(color);jb.add(intall);
< p data-track="45">4. Add font size 12, 15, 18, 20

fontsize.add(twelf);fontsize.add(fiveteen);fontsize.add(eighteen);fontsize.add(twenty);this.setJMenuBar(jb);
< p data-track="47">The effect picture is as follows:

5. Add font

font.add(song);font.add(hei);font.add(kai);

The effect picture is as follows:

6. Add glyphs Regular, Bold, Italic

fontstyle.add(chang);fontstyle.add(jia);fontstyle.add(qing);

The effect picture is as follows:

7. Add color red, green, blue

color.add(red);color.add(green);color.add(blue);

The effect picture is as follows:

8. Add settings Change wallpaper

intall.add(swap);

The effect picture is as follows:

The font size, The font, font style, color, and settings are added to the JMenuBar menu bar, and the menu items in the font such as HeiTi and SongTi are added to the menu. The same goes for other font sizes, font styles, colors, and settings add-ons!

Then implement the function Please see the step-by-step tutorial on how to create a simple storybook in Java (Part 2)!


4. Summary

This article mainly introduces the basic use of JPanel, JButton, JLabel, JTextArea, JMenu, JMenuItem and other components, as well as the corresponding event processing . These codes are relatively simple, and it is also a simple small case. I hope it will be helpful to your study. In the next article, we will carry out specific implementation, so stay tuned!

Articles are uploaded by users and are for non-commercial browsing only. Posted by: Lomu, please indicate the source: https://www.daogebangong.com/en/articles/detail/Teach%20you%20to%20create%20a%20simple%20storybook%20with%20Java%20Part%201.html

Like (810)
Reward 支付宝扫一扫 支付宝扫一扫
single-end

Related Suggestion