Simple server and client code instances
Exercise the application of socket, datainputstream, dataoutputstream, thread, and actionlistener. The function is very simple: Enter the user name in the client and press enter to check whether the user name is valid. I have defined that only jiqimiao is valid.
The server code is as follows:Import java. AWT .*;
Import java. Io .*;
Import java.net .*;
Import java. util .*;
Import javax. Swing .*;
/*** Server programs* @ Author Zuo Jie**/Public class tests
The top-level container is worth a container component that accommodates other containers, including the JFrame class, Jwindows class, JDialog class, JApplet, and so on.Top-level container classes in swingSwing offers three top-level container classes: Jframe,jdialog and JApplet. When using these container classes, keep in mind the following guidelines.To be displayed on the screen, each GUI component must
Note: The image is displayed on the label. Common APIs are used. When using jframe, close the window and exit debugging.Code.
Complete code, compiled and executed
Import javax. ImageIO. *; // For ImageIO. ReadImport java. AWT. *; // For jframe and jlabel etcImport javax. Swing. *; // For jframe and jlabel etcImport java.net. *; // For URLImport java. Io. *; //
ArticleDirectory
2. A problem when converting a common application into an applet
1 Java, Conditional compilation
Java does not have a Conditional compilation mechanism similar to C/C ++ Because Java considers itself cross-platform, the previous Conditional compilation was designed to solve the problem of C/C ++ quick platform. However, Conditional compilation and translation can also be used for debugging.
ProgramYou can introduce the assertion mechanism commonly used in C, that is, cr
So far we have been in touch with the Java command line, but in order for the user to use, there must be a graphical interface, so this chapter is mainly about how to use the GUI (graphical user interface)Create a gui:javax.swing.*the layout-related content in this chapter is the content of the javax.swing package, the common components are jframe,jbutton,jradiobutton,jcheckbox,jlabel,jlist,jscrollpane,jslider,jtextarea,j Textfield,jtable, etc.Create
1. Create a normal formFirst, create a simple interface, which uses BorderLayout and places 5 jbuttons in it, as shown in the following code,Public class ShapedFrame extends JFrame {
Private static final long serialVersionUID =-2291343874280454383L;
Private JButton centerButton = new JButton ("Center ");
Public ShapedFrame (){Super ("Shaped Frame ");Setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE );InitUI (
The last introduction of a single button drag principle, today to a joint operation, the implementation has been thought to create a listenerError, add to the various components, the result of yesterday night accidentally came up with a solution. And it's the super-simple kind, alas.! Sometimes it's not a good thing to think more.Drag a single component: http://www.cnblogs.com/Ruby517/p/6507001.html In fact, you want multiple components to be able to respond to drag events. Then write them a pa
Package com.swing;Import java.awt.*;Import javax.swing.*;public class SWING01 extends jframe{/*** 1. What is Swing* Swing is the ui--of the Java platform and it acts as a software that handles all interactions between users and computers. It actually acts as an intermediary between the user and the computer.** 2.Swing Bag* Java.lang.Object--->java.awt.component-->java.awt.container-->java.swing.jcomponent** 3. Components* 1.JFrameJFrame is the main wi
The previous article explains JFrame, JPanel, which already involves the use of empty layouts. While Java can pinpoint components in pixels, there will be some display differences in different systems, so that the display is not the same, so Java provides a layout manager to make the graphical interface written with good platform independence. Note: All layout managers are used for containers, including top-level containers and intermediate containers
The applet currently does not have a dialog function, only the most basic login, the function of displaying the chat recordLogin interfaceImport Javax.swing.JFrame;Import Javax.swing.JLabel;Import Javax.swing.JButton;Import Javax.swing.JTextField;Import Javax.swing.JPasswordField;Import Javax.swing.JPanel;Import Java.awt.GridLayout;Import Java.awt.BorderLayout;Import Java.awt.FlowLayout;public class Qqlogin extends jframe{Private JLabel Labuser; User
can be flowlayout.left,flowlayout.center,flowlayout.right.3.FlowLayout (int aligment,int horz, int vert), set alignment, and set the horizontal spacing between the components Horz and vertical spacing vert, using the Superclass container Method SetLayout () to set the layout for the container. For example, code setlayout (New FlowLayout ()) sets the FlowLayout layout for the container. The method of adding a component to a container is add (component name).
Two. BorderLayout layout (default la
Four types of information balloon in Java
tags (space-delimited): Java
Four ways to eject a pop-up balloon in Java:confirmdialog-Confirmation dialog box, the user clicks "YES" or "No"inputdialog-Enter a cue boxmessagedialog-Information Balloonoptiondialog-combination of the remaining three frame bodiesExample:Confirmdialog:Joptionpane.showconfirmdialog (New JFrame (). Getcontentpane (),"User name is registered. "," System Information ", Joptionpane.y
GUI programming--Primary articles
I. Introduction to the ELEMENTS
1.JFrame class:
1 Concept: Its strength is called a window, belonging to the bottom of the container, you can directly interact with the operating system.
2) commonly used methods:
A.jframe () method to create an untitled window
B.jframe (Strings) method creates a window with the title s
C.public voidsetvisible (BOOLEANB) Settings window is visible
D.public void Dispose () to undo th
interface elements, they differ in important ways: AWT relies on the main platform to draw user interface components, and swing has its own mechanism to draw and manage the interface component in the window provided by the main platform. The most obvious difference between swing and AWT is the look and feel of the interface components, and AWT runs the same program on different platforms, and there may be some differences in the appearance and style of the interface. However, a swing-based appl
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.