In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 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 build a simple takeout system". In the operation of actual cases, many people will encounter such a dilemma, so 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 rapid development of the Internet era, convenient people's life, improve the quality of life, takeout system came into being.
People also like to enjoy the treatment of "staying at home, delicious food at home", which promotes the rapid development of the online food ordering industry.
[II. Project objectives]
1. Design an application-takeout system with text and pictures to show that by selecting one or more foods, you can choose one or more portions of each food, click on the settlement, and calculate the total price.
two。 Realize title text scrolling and color timing change.
3. How much to realize the consumption of free distribution fees and how much consumption is fully reduced.
[III. Project implementation]
Using eclipse software development, first put up the effect picture, as shown in the following figure.
You can see that there are words and pictures on the interface, by selecting one or more foods, each food can choose one or more portions, settlement function, title text scrolling and color change function.
Next, the editor will take you to carry out the specific implementation, and the specific implementation steps are as follows.
[IV. Implementation steps]
First, realize the window of the shopping cart of the takeout system.
Public static void main (String [] args) {/ / TODO Auto-generated method stub Takeout t = new Takeout (); t.setTitle ("Raoyang takeout"); t.setSize (720550); t.setVisible (true);}
Create a Takeout 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
Second, add text to realize
1. The components used are JPanel and JLabel.
two。 Add member variables of the Takeout class
Public class Takeout extends JFrame {/ / member variable private JPanel panel01 = new JPanel (); private JLabel label01 = new JLabel ("Welcome to Raoyang takeout system!")
3. Add a text description
The Takeout class constructor:
Takeout () {label01.setFont (new Font ("boldface", Font.PLAIN,30); label01.setForeground (Color.BLUE); panel01.add (label01); panel01.setOpaque (false); / / set transparent this.setLayout (new BorderLayout ()); this.add (panel01,BorderLayout.NORTH); this.getContentPane () .setBackground (c)
4. Text (label01) sets the display effect
1) setFont (newFont (String font, int style, int font size))
Font: TimesRoman, Courier, Arial, etc.
Style: three constants lFont.PLAIN, Font.BOLD, Font.ITALIC
Font size: the size of the word (pounds)
2) setForegound sets the foreground color
3) setOpaque setting control is transparent (ture or false)
4) BorderLayout of the layout manager (boundary layout)
The boundary layout manager divides the layout of the container into five locations: CENTER, EAST, WEST, NORTH, and SOUTH. The corresponding order is: upper north (NORTH), lower south (SOUTH), left west (WEST), right east (EAST), middle (CENTER).
5. Boundary layout feature
1) components can be placed in any of these five locations. Assuming no location is specified, the default location is CENTER.
2) the south and north position controls each occupy a row, and the width of the control will actively cover the whole row. The east, west, and middle positions occupy a row; if there are no controls in the east, west, south, and north positions, the intermediate controls will actively cover the entire screen. If there are no controls in the east, west, south, or north locations, the intermediate position controls will take the initiative to occupy the locations where there are no controls.
3) it is the default layout for forms, frame content panes, dialog boxes, and so on.
6. GetContentPane.setBackground (c) initializes a container. Setting the background RGB color needs to be defined in the member variable.
Private Color c = new Color (197228251)
Add food text, quantity (button) and picture
Need to add JPanel, JCheckBox, JButton, JLabel, and so on.
1. Add member variables of the Takeout class
Private JPanel panel02 = new JPanel (); private JCheckBox check [] = new JCheckBox [9]; / / text (checkbox) private JButton amount [] = new JButton [9]; / / quantity (button) private JLabel food [] = new JLabel [9]; / / Food picture private int num [] = new int [9]; / / quantity array
two。 Set the properties of the component in the constructor of the Takeout class
Reference code
Takeout () {. Check [0] = new JCheckBox ("ice cream 3.0yuan", false); check [1] = new JCheckBox ("French fries 6.0yuan", false); check [2] = new JCheckBox ("popcorn 8.0yuan", false); check [3] = new JCheckBox ("hot dog 10.0yuan", false); check [4] = new JCheckBox ("hamburger 11.0yuan", false) Check [5] = new JCheckBox ("Big Mac 16.0 yuan", false); check [6] = new JCheckBox ("Coke 6.0yuan", false); check [7] = new JCheckBox ("juice 8.0yuan", false); check [8] = new JCheckBox ("beer 6.0yuan", false); for (int iBeer
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: 0
*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.