The basic idea of Java GUI program is based on JFrame, which is the object of window on screen, it can be maximized, minimized and closed. Swing is a development kit for developing the Java application user interface. Based on the Abstract Window Toolkit (AWT), you can use any pluggable styling for cross-platform applications. Swing developers can use Swing's rich, flexible features and modular components to create elegant user interfaces with little
Add components to the framework: eg.JFrame frame=new JFrame ("JFrame add");Java.awt.Container Container=frame.getcontentpane ();//You can return to the contents pane of the frame, the Contents pane is Java.awt.Container instanceJButton jbtok=new JButton ("OK");Container.add (Jbtok);//The method adds a component instance to the containerContainer.remove (Jbtok);//Delete InstanceThe component is placed on the
Template Method Pattern JFrame specific explanationThis address: Http://blog.csdn.net/caroline_wendyReference Template Method pattern: http://blog.csdn.net/caroline_wendy/article/details/32159455Template method Pattern, Java JFrame using template method mode, paint () is a method that can be overwritten,Overlay Paint () method to customize the JFrame display scr
Set JFrame background picture from two ways:
1.Jpanel class Paintcomponent (Graphics g) Redraw background picture
2. Use Layeredpane to add depth to swing controls Allow the build to overlap at the required time
from low to High level is: Default,palette,modal,popup,drag
Run the show: Upload later
API query:Jpanel:http://docs.oracle.com/javase/7/docs/api/javax/swing/jpanel.htmlGraphics:http://docs.oracle.com/javase/7/docs/api/java/awt/graphics.ht
There are two kinds of things that can be put into jframe, containers and components. You can see these clearly in the graphical interface of Jigloo.Common containers (containers) have these:JFrame interface with caption and Close buttonJPanel PanelJScrollPane panel with scroll barJSplitPane Panel with sub-columnsJTabbedPane Panel with TAB structureJDialog dialog boxThese are the common components (component)JButton buttonJLabel label (used to display
Just touch the Java text box drawing knowledge point, and then can follow the teacher's reminders to do some simple game, to jframe deepen, the following on the greedy snake give some source code, in fact, the implementation of the code is not much, just a little processing can be understood, the following code has comments!First Class Shake classImport Java.awt.Color;Import Java.awt.Graphics;Import Java.util.Random;public class Snake {public int w;//
Recently learning swing, in various demos need to build JFrame, so I decided to build JFrame code to paste up, and then directly copied and pasted. Public Static voidMain (string[] args) {//Create a form and specify a titleJFrame frame =NewJFrame ("Boxlayoutdemo"); //set up the content panel to modify as neededFrame.setcontentpane (NewBoxlayoutdemo ()); //quit a program after closing a formframe.setdefaultc
Frame.addwindowlistener (New Windowadapter () {@Overridepublic void windowclosing (WindowEvent e) {int choose = Joptionpane.showconfirmdialog (null, "Are you sure you want to exit?") ","Message hint", joptionpane.yes_no_option);if (choose = = Joptionpane.yes_option) {System.exit (0);} else if (choose = = Joptionpane.no_option) {return;//here is missing JFrame, but the program does not exit. It should just be hidden. I print out the Visible property is
A lot of times we get an interface, do not want the default border, or do not want the top right corner of the maximum button, such as the QQ panel does not have the maximum button.
But I checked a lot of information that can not directly remove the maximum button, you must have the entire border and the title are removed, and then draw their own.
The test code is also simple:
"1" jframe no border without a title
"2" Add a background picture (there a
There are a lot of people who just started to learn swing often ask JFrame close when asked whether to close, that is, a dialog box to let users click to select Yes or no, in fact, a little bit to see the source code can find the answer. We found out where the shutdown happened, and we intercepted it in that place, and looking at the source can tell you there is one way to do this in JFrame:
protected void
Each time you write a graphical program, only manually adjust the JFrame frame size to display the contents. Using validate () does not work, and pack () can solve this problem.Pack ()//is automatically adapted to size. When writing a program, if preferred size is defined, the frame size is drawn according to the preferred size, or the component within the container is sized to fit.Vailate ()//is resized, provided the size has been set (SetSize () has
1. DefinitionSwing (Hevay weight component) is a lightweight component relative to AWT (Hevay weight component). Swing is written in Java Code, which solves the problem that Java cannot cross the platform because of the window class, so that the window functions are cross-platform and malleable, and swing occupies less system resources. The essay introduces Swing-jframe. 2. Methodsvoid Add (): Add componentvoid Settitle (String title): Set Captionvoi
Effect:These days to learn Java, because the study is not very good, there is nothing to what can work, but after all, it is just beginning to seriously learn, but also encountered a lot of problems;First of all1. JFrame's borderless settings: jframe.setundecorated (TRUE); This property is mentioned many on the net, is in JFrame in the case of display (jframe.setvisible (true);) Can remove the JFrame defaul
frame window close function//re-import the related package to This.addwindowlistener (new Windowadapter () {@Override public void WINDOWCLOsing (WindowEvent e) {system.exit (0);}});JFrame window Add close function setdefaultcloseoperation (exit_on_close); The difference I find out occasionally, but don't know why? JFrame inside if you have a TextBox control and a drop-down list box control, when you enter a
A lot of times we get an interface, do not want the default border, or do not want the top right corner of the maximum button, such as the QQ panel does not have the maximum button.
But I checked a lot of information that can not directly remove the maximum button, you must have the entire border and the title are removed, and then draw their own.
The test code is also simple:"1" jframe no border without a title"2" Add a background picture (there
This article describes the use of JFrame to complete the dynamic simulation clock, draw the clock in the panel and extract the current moment of the system, the main method to suspend the thread 1 seconds, refresh the panel.
The implementation code is as follows
Import javax.swing.*;
Import java.awt.*;
Import java.util.*;
Import Java.lang.Thread;
Import Java.text.DecimalFormat;
public class Stillclock extends JPanel {/** * @param args * * pr
I made a student management Applet and needed to call the display subclass window in the parent class window. However, when the subclass window is closed, the parent class window is also closed, then I checked it to solve the problem:
1. I used frame. setdefadefacloseoperation (jframe. exit_on_close) to close it, and exit indicates that the Java application is exited. So I changed it to frame. setdefadefacloseoperation (
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.