Traditional Culture Encyclopedia - Almanac inquiry - Want to know how to make such a historical query interface with java swing?
Want to know how to make such a historical query interface with java swing?
One: The main layout is the boundary layout. Today yesterday the day before yesterday was the grid layout of 1 row 1 column.
Two: click on today, yesterday, tomorrow, and the middle component to change the content, which can be realized by JTabbedPane.
Of course, it can also be implemented with JLabel or JButton. When you add a click event, you only need to change the intermediate component.
Three: the blue indicator can also change the appearance of the component, or change the background picture or draw some colors when accepting the click event.
Recommended practice:
If you want the same imitation, it is recommended not to use the JTabbedPane component, but to make yesterday, today and so on into buttons. . ? Then when you click, change the content.
Simple imitation
The code is as follows
Import? javax . swing . *;
Import? Java . awt . *;
Public? Class? SwingDemo? Extension? JFrame? {
Public? SwingDemo()? {
JPanel? jp? =? New? JPanel (new? Process layout (process layout. Left));
JLabel? jl? =? New? JLabel (Historical Records); //? Text label
Jl.setFont (new? Font ("Song Ti", font. Bold? 32)); //? Set the font of the text label.
JTextField? jtf? =? New? JTextField(8); //Text box, length 8
JButton? jb? =? New? JButton(" search "); //button
jp . add(JL);
jp . add(jtf);
jp . add(JB);
Add (jp,? BorderLayout。 North); //? Release? Jp to the north
JTabbedPane? jtp? =? New? JTabbedPane(); //? label
JPanel? jp0? =? New? JPanel (new? Process layout (process layout. Left)); //? Streaming layout from left to right,
JLabel? jl 1? =? New? JLabel ("Today's History:");
jp 0 . add(JL 1);
Jtp.add ("today ",jp0); //? Tab panel add? What's the topic? Today? The corresponding content component is jp0.
JTextArea? jta? =? New? JTextArea();
Jta.append ("Yesterday's History:");
Jtp.add ("Yesterday", JTA);
JPanel? jp 1? =? New? JPanel();
Jp 1.setBackground (color. Orange);
Jtp.add ("the day before yesterday", JP1);
jtp . settab placement(JTabbedPane。 Left);
Add (jtp);
SetTitle ("main window"); //? title
setSize(620,? 480); //? size
setLocationRelativeTo(null); //? centre
setDefaultCloseOperation(EXIT _ ON _ CLOSE); //? Quit the program after closing the window.
set visible(true); //? Window visible
}
Public? Static electricity Invalid? main(String[]? args)? {
New? swing demo();
}
}
- Related articles
- A similar evil spirit novel
- Good days in the old yellow calendar
- Did Ren Shen commit Tai Sui on May 29th?
- 9 1 1 China Gregorian calendar
- Advertisement-free almanac mobile phone
- 93 calendar
- 7 1 What is the zodiac?
- Urgent request: 20 1 1 registered auspicious male 1985.2.25 is a cow female 1985.2.7 is a cow (lunar calendar).
- Oppo creation schedule
- Let you kill four feng shui ornaments on the mahjong table?