Steps of visual development of Java JFrame

Tip: After the article is written, the table of contents can be automatically generated. How to generate it can refer to the help document on the right


foreword

JFrame can make a form similar to the QQ login function. Through JFrame, Java code can be used to realize the form function, which is generally used for the development of C (client) of CS projects;

1. What is JFrame?

Using JFrame, you can write java code by yourself, or install the windowbuilder plug-in in eclipse, so that you can use the windowbuilder plug-in to quickly create and operate the form visually, and quickly realize the development of programming;

The general steps for visual development of JFrame form through eclipse using windowbuilder plug-in are as follows:

2. Use steps

1. Add the windowbuilder plug-in to eclipse:

1. First check your eclipse version:

 

 

2. Select the http address of the corresponding version number on the windowbuilder plug-in website through the eclipse version: URL: WindowBuilder | Download | The Eclipse Foundation

 

 

3. Then install the windowbuilder plug-in in eclipse:

  eclipse-->help-->Install New SoftwareOpen:

Name: Just write a name, it is best to know the name, such as: windowbuilder

Locatioin: It is to write the address in the http column just obtained according to the eclipse version;

In the next step, select all, then the next step until complete, then restart eclipse to complete;

2. Create a windowbuilder java project in eclipse, and create a java entity class for visual development:

1. Create a java project through windowbuilder:

 

2. Add jar packages: DJNativeSwing-1.0.0.jar, DJNativeSwing-SWT-1.0.0.jar, org.eclipse.swt.win32.win32.x86_64-4.3.jar (this jar package depends on whether the computer is 32-bit or 64-bit bit to download, in this case a 64-bit operating system)

3. Create a java entity class through windowbuilder: new--->other:

Click Design for visual development

Example of embedding html interface in Swing:


import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;  
import java.awt.event.ItemEvent;  
import java.awt.event.ItemListener;
import java.util.UUID;

import javax.swing.BorderFactory;  
import javax.swing.JCheckBox;  
import javax.swing.JFrame;  
import javax.swing.JPanel;  
import javax.swing.SwingUtilities;

import com.nari.slsd.hd.common.FuncActionItem;
import com.nari.slsd.hd.common.IRunEntry;
import com.nari.slsd.hd.common.IStaticMsgCard;
import com.nari.slsd.hd.common.MessageBody;

import chrriis.common.UIUtils;  
import chrriis.dj.nativeswing.swtimpl.NativeInterface;  
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;  
  
@SuppressWarnings("serial")  
public class ShowHtml extends JPanel implements IRunEntry,IStaticMsgCard {  
  
    public ShowHtml() {  
        super(new BorderLayout());  
        JPanel webBrowserPanel = new JPanel(new BorderLayout());  
        webBrowserPanel.setBorder(BorderFactory  
                .createTitledBorder("电能量系统"));  
        final JWebBrowser webBrowser = new JWebBrowser();  
        webBrowser.navigate("http://172.21.99.15:8008/wisdomServer/wisdomClient/main.html");  
        this.add(webBrowser);
        webBrowserPanel.add(webBrowser, BorderLayout.CENTER);  
        add(webBrowserPanel, BorderLayout.CENTER);  
        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4));  
        JCheckBox menuBarCheckBox = new JCheckBox("菜单栏", webBrowser  
                .isMenuBarVisible());  
        menuBarCheckBox.addItemListener(new ItemListener() {  
            public void itemStateChanged(ItemEvent e) {  
                webBrowser  
                        .setMenuBarVisible(e.getStateChange() == ItemEvent.SELECTED);  
            }  
        });  
        buttonPanel.add(menuBarCheckBox);  
        this.add(buttonPanel, BorderLayout.SOUTH);  
    }  
  
    public static void main(String[] args) {  
        UIUtils.setPreferredLookAndFeel();  
        NativeInterface.open();  
        SwingUtilities.invokeLater(new Runnable() {  
            public void run() {  
                JFrame frame = new JFrame();  
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
                frame.getContentPane().add(new ShowHtml(),  
                        BorderLayout.CENTER);  
                frame.setSize(800, 600);  
                frame.setLocationByPlatform(true);  
                frame.setVisible(true);  
            }  
        });  
        NativeInterface.runEventPump();  
    }

	@Override
	public UUID getAddr() {
		return null;
	}

	@Override
	public int getGroup() {
		return 0;
	}

	@Override
	public int getUsage() {
		return 0;
	}

	@Override
	public Object receiveMessage(IStaticMsgCard arg0, MessageBody arg1) {
		return null;
	}

	@Override
	public void setAddr(UUID arg0) {
		
	}

	@Override
	public IStaticMsgCard getPanelMessageCard() {
		return null;
	}

	@Override
	public String getTitle() {
		return "电能量";
	}

	@Override
	public Object invoke(Container arg0, FuncActionItem arg1) {
		// 将界面返回的出口
		return this;
	}  
}  

 
 

Summarize

The above is what I want to talk about today. This article only briefly introduces the use of JFrame. If you have any questions, you can leave a message.

Guess you like

Origin blog.csdn.net/wzw_wwl/article/details/124188378