. actionreceivmed (New actionevent ("", 0 ,""));}Public static void main (string [] ARGs ){Console. Run (New showaddlisteners (), 500,400 );}}///:~
Import niutool. console and introduce a console tool. The source code is as follows:
Package niutool;
Import javax. Swing .*;
Import java. AWT. event .*;
Public class console {
// Create a title string from the class name:
Public static String title (Object O ){
String T = O. getclass (). tostring ();
// Remove the word "class ":
If (T. indexof ("cla
, JLayeredPane, JList, JMenuBar, Joptionpane,jpanel,JPopupMenu, JProgressBar, JRootPane, Jscrollbar, JScrollPane, Jseparator, JSlider, JSpinner, JSplitPane, JTabbedPane, JTable, Jtableheader, JTextComponent, JToolBar, JToolTip, JTree,
JViewport
There are two main types of swing containers, the window and Panel,window windows are divided into two types: JFrame (Form) and JDialog (dialog), the Panel panel has two types: JPane
The single-choice button is to specify one of Multiple display information. In swing, you can use JRadioButton to complete the operation of a group of single-choice buttons.
Package com. beyole. util; import java. awt. container; import java. awt. gridLayout; import java. awt. event. windowAdapter; import java. awt. event. using wevent; import javax. swing. borderFactory; import javax. swing. buttonGroup; import javax. swing. JFrame; import javax. sw
components and containers. 13.2 common forms 13.2.1 JFrame Forms 1. JFrame forms are a container, which is the carrier of each component in the Swing program. JFrame can be considered as a container that carries these Swing components. 2. syntax format: JFrame jf = new JFrame
.*;
import java.awt.*;
public class Hellocsdn
{
public static void Main (string[] args)
{
hellocsdnframe frame=new hellocsdnframe ();
frame.setdefaultcloseoperation (jframe.exit_on_close);
frame.show ();
}
}
/** This part we construct a new frame Hellocsdnframe
*/
-------------------------------------------------------------------------
class Hellocsdnframe extends jframe{
public hellocsdnframe ()
{
settitle ("Hello cs
The following example program is to add three buttons to a panel, add three listener objects to act as a button, and when clicked on a different button, the background color of the panel is changed to the corresponding color:
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*; public class buttonframe{public static void Main (string[] args) {eventqueue.invokelater (()-G T
{jframe frame= new creatbuttonframe ();
frame.s
The third card layout can be used to complete a simple lottery program, which is quite interesting.One: Flow layout flowlayoutImplementation code:Import java.awt.FlowLayout; import javax.swing.JFrame; import Javax.swing.JButton; class tester{public static void Main (String args[]) { JFrame frame = new JFrame ("streaming layout"); Frame.setlayout (New FlowLayout (flowlayout.center,3,3));
/*Chestnuts Learn about Swing*/Import javax.swing.*;public class Test_swing extends JFrame { Inherit JFrame top-Level container class (classes that can add other swing components) JButton jb1 = null; public static void Main (string[] args) { Test_swing win = new test_swing (); } constructor function Public test_swing () { JB1 = new JButton ("button"); This.add (JB1);
can use, respectively:· JFrame: Used to design an application similar to a window form in a Windows system.· JDialog: Similar to JFrame, except that JDialog is used to design dialog boxes.· JApplet: Used to design Java applets that can be embedded in a Web page.If you need to use swing to make a window class program, our code should look like this:
Finally successfully implemented how to set the background picture for the JFrame window. Here is an example, please learn from Swring's friends.Import java.awt.*; Import javax.swing.*; Import Java.awt.Container; public class Framebg {public Framebg () {} public static void Main (string[] args) {JFrame frame=new JFrame ("Background map Settings"); fr Ame.setdefau
Computer questions (Elementary)-How to Use arrays to implement notepad (Java)
Use java to implement a Notepad program and record the keys. The Code is as follows:
Package com. java. test; import java. awt. graphics; import java. awt. event. keyEvent; import java. awt. event. keyListener; import javax. swing. JFrame; import javax. swing. JPanel; public class Book {public static void main (String [] args) {JFrame
Addphotolabel (JFrame jfr, int x, int y, int. wide, int high, String URL) {icon icon = new Imageic On (URL);//Add the image to the label JLabel Photolabel = new JLabel (icon);p hotolabel.setbounds (x, Y, wide, high); Jfr.add (Photolabel);} Window properties public static void Windowattribute (JFrame JFR, int. wide, int high, string backurl, string title) {//Set window icon WINDOWSI Con (JFR);//Window Cente
The xmlencoder class is a complementary replacement of objectoutputstream and can be used to generate the text representation of the JavaBean. It is used in the same way as the binary representation used to create a serializable object using objectoutputstream.
The xmldecoder class is used to read XML documents created using xmlencoder. Its purpose is similar to objectinputstream. For example, you can use the followingCodeSegment to read the first object defined in XML format (written through
compile and run to see the results of the implementation.
1. Top-level container
What is a top level container? When we use Java for graphic programming, where does the diagram draw? We need a container that can provide graphics, a container that is called a top-level container, and you can think of it as a window. Top-level containers are the basis for graphic programming, and everything that is graphical must be included in the top-level container. In swing, we have three top-level contai
height of each component are 0 by default. In other words, it is necessary to use setdividerlocation (double) after the main form setvisible (true). The following is an example: Package tl1_zbe.info. stratch; import javax. swing. jframe; import javax. swing. jsplitpane; import Java. AWT. borderlayout; import javax. swing. jpanel; public class mainframe extends jframe {public static void main (string [] AR
With the gradual development, I found that I did not understand anything, And suddenly lost my sense of superiority. Originally, what programmers want to do with this kind of superiority will only let you go downhill, continue to learn and understand and try again to survive. Let's go back to the basics. Otherwise, we will encounter a lot of problems in the future.
There are two methods for my understanding about the response of actionlistener. First, you put it in a new class, implement the act
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.