In the graphical interface programming, the button JButton need to lay out the position of the button, change the button size.1) button InitializationJButton button = new JButton ()/* In the new JButton () bracket, you can add the character displayed by the button, etc.JButton button = new JButton ("Jbuttonexample")How
Java Image Interface Development Simple example
JTextArea, JScrollPane, JPanel, JButton application examples, through the ' Insert Text ' button function, write Test text, line-wrapping function can be used for line and no line, the code is as follows: Import java.awt.BorderLayout;Import java.awt.event.ActionEvent;Import Java.awt.event.ActionListener;Import Javax.swing.JButton;Import Javax.swing.JFrame;Import Javax.swing.JPanel;Import Javax.swing.JScr
Java JButton style settings (some functions we should know) (to), javajbutton
1. Set JButton size 2 -- Because JButen belongs to the small device type, the general setSize cannot be set to the size of the device, so we generally use 3 buttons. setPreferredSize (new Dimension (30, 30); 4 // (30, 30) is the size of the button you want to set 5 2. Set 6 transparent to JBut
Java JButton button monitoring, when more than one button to do things can be used for the loop (such as calculator 1-9) Save effort.The variables can only be final or static when listening, but these are obviously not possible in the For loop, so we add a final variable in the loop.Hey, easy to fix.Package Com.xinbo;Import Java.awt.FlowLayout;Import Java.awt.GridLayout;Import java.awt.event.ActionEvent;Import Java.awt.event.ActionListener;Import Java
Note: According to the suggestions of yigemaser, jfml, and crazyjavar, I would like to express my gratitude for the help of the three parties!
When writing a UI application, it is usually in some event processing processes, especially when the processing is time-consuming, and it is hoped that some progress information will be displayed to the user in a timely manner. Generally, a text control is used to display the progress information. For example, in the following program, there is a jtextpan
In some layout S such as flowlayout and borderlayout, jbutton uses setsize () to set the size. You can use the setpreferredsize method to set the size. For example:
Public static void main (string [] ARGs ){Jframe frame = new jframe ();Frame. setdefaclocloseoperation (jframe. exit_on_close );Frame. setlayout (New flowlayout ());Jbutton button = new jbutton ("tes
Java image interface development example
Simple Application of jbutton and events, a small example of a calculator, the Code is as follows:Import java. AWT. borderlayout;
Import java. AWT. gridlayout;
Import java. AWT. event. actionevent;
Import java. AWT. event. actionlistener;
Import javax. Swing. jbutton;Import javax. Swing. jframe;Import javax. Swing. jpanel;
/*** Calculator instance* @ Author Zuo Jie
1, the JButton size of the settingbutton.setpreferredsize (New Dimension (30,30)); //(30,30) is the size of the button you want to set 2. Transparent setting for JButtonbutton.setcontentareafilled (false);3. Set the border of the button to remove the JButtonbutton.setborderpainted (false);4, the setting of JButton add iconinstantiate an Icon object imageicon image = new ImageIcon (Icons[i]), instantiates a
11, setting the size of the JButton2 --Because Jbuten is a small device type, the general setsize can not be awakened to the size of the setting, so generally we use3Button.setpreferredsize (NewDimension (30,30));4 //(30,30) is the size of the button you want to set52, transparent settings for JButton6 --the button is set to transparent so that it does not block back background7Button.setcontentareafilled (false);83, set the border of the button to remove the JButton9 --If sometimes your bu
Phenomenon:
An extension of the JButton class button that has a different look when the mouse is moved, moved, or clicked
Solution:
import javax.swing.*; import javax.swing.border.*; import java.awt.event.*; import java.awt.*; /** * Title: * Description: * Copyright: * Company: * @author * @version 1.0/An extension of the /** * JButton button that has a different appearance when the mouse is moved, r
Reproduced from: http://blog.sina.com.cn/s/blog_6eef4a86010140or.html
JLabel, JButton, etc. cannot be wrapped in "\ n", but they support HTML, so they can be implemented with Attach a small procedure:
01PackageCom.kaso.Test;0203ImportJavax.swing.JFrame;04ImportJavax.swing.JLabel;0506Public classTestframeextendsJFrame {07PrivateJLabel label =NewJLabel ("");0809 PublicTestframe () {10 This. Add (label);One String s = Fun ();Label.settext ("1
Five common la s of Swing and wing in java
1. Border layout (BorderLayout)
2. FlowLayout)
3. GridLayout)
4. BoxLaYout)
5. Empty layout (null)
There are two other layout S: GridBagLayout (grid package layout) and CardLayout (card layout)
Note: The default layout of JFrame and JDialog is BorderLayout, while that of JPanel and Applet is FlowLayout.
Sample Code for border layout:
Import java. awt. borderLayout; import javax. swing. JButton; import javax.
Java --- Swing Interface Development Summary, java --- swing Interface
I. graphical interface of java
1. awt java. awt
The graphic interface launched before jdk1.4 is written in c/c ++, which is not cross-platform.
2. swing javax. swing
Jdk1.4 graphic interface, good cross-platform
Ii. common components
1. Container Components
The top-level container of the JFrame form class (the default layout is the border layout and cannot be added to each other by yourself)
The most flexible container of the
Boundary layoutpublic class Borderlayouttest extends jframe{Public Borderlayouttest () {This.setsize (900,600);This.setdefaultcloseoperation (Jframe.exit_on_close);This.settitle ("Border layout");This.setlocationrelativeto (null);//Set the form to centerThis.addcontent ();This.setvisible (TRUE);}public void Addcontent () {Container con = This.getcontentpane ();Con.setlayout (New BorderLayout ());JButton btn1 = new
The code is as followsImport Java.awt.*;import java.awt.event.*;import Javax.swing.*;import Java.util.vector;public class Calculator {Strin G str1 = "0"; Operand 1 Initial value must be 0 for program security String str2 = "0"; Operand 2 String signal = "+"; Operator String result = "";//result//status switch int k1 = 1;//switch 1 used to select input direction to be written to str2 or str2 int k2 = 1;//Switch 2 sign key number k2 Gt;1 instructions are 2+3-9+8 such a multi-sign operation int K3
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.