javaswing视频教程(java swing怎么嵌入js)

本文目录
java swing怎么嵌入js
import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserCommandEvent;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserEvent;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserListener;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserNavigationEvent;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserWindowOpeningEvent;
import chrriis.dj.nativeswing.swtimpl.components.WebBrowserWindowWillOpenEvent;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import com.mohe.utils.system.L;
/**
* 主窗体
*
* @author dxm
*
*/
public class MainFrame extends JFrame {
private static final long serialVersionUID = -6348199501339114346L;
// 最后操作时间
public long lastTime = new Date().getTime();
// 浏览器窗体
private JWebBrowser webBrowser = null;
private JLabel lbl = null;
private JPanel panel = null;
public int pageFlag = 1;
/**
* 构造器
*/
public MainFrame() {
initData();
initGUI();
addListance();
}
private void initData() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
this.setUndecorated(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(600, 500);
this.setLocationRelativeTo(null);
this.setSize(toolkit.getScreenSize());
this.setLocation(0, 0);
webBrowser = new JWebBrowser();
webBrowser.navigate(Config.local + Config.index);
webBrowser.setBarsVisible(false);
webBrowser.setMenuBarVisible(false);
webBrowser.setLocationBarVisible(false);
webBrowser.setButtonBarVisible(false);
webBrowser.setStatusBarVisible(false);
ImageIcon icon = new ImageIcon(System.getProperty("user.dir") + "\\城市.gif");
File img = new File(System.getProperty("user.dir") + "\\" + Config.img);
if (img.exists()) {
icon = new ImageIcon(img.getAbsolutePath());
}
lbl = new JLabel(icon);
panel = new JPanel(new BorderLayout());
}
private void initGUI() {
panel.add(webBrowser, BorderLayout.CENTER);
this.setContentPane(panel);
}
private void addListance() {
webBrowser.addWebBrowserListener(new WebBrowserListener() {
@Override
public void windowWillOpen(WebBrowserWindowWillOpenEvent arg0) {
lastTime = new Date().getTime();
L.info("___________ windowWillOpen");
}
@Override
public void windowOpening(WebBrowserWindowOpeningEvent arg0) {
lastTime = new Date().getTime();
L.info("___________ windowOpening");
}
@Override
public void windowClosing(WebBrowserEvent arg0) {
lastTime = new Date().getTime();
L.info("___________ windowClosing");
}
@Override
public void titleChanged(WebBrowserEvent arg0) {
lastTime = new Date().getTime();
L.info("___________ titleChanged");
}
@Override
public void statusChanged(WebBrowserEvent arg0) {
lastTime = new Date().getTime();
L.info("___________ statusChanged");
}
@Override
public void locationChanging(WebBrowserNavigationEvent arg0) {
lastTime = new Date().getTime();
L.info("___________ locationChanging");
}
@Override
public void locationChanged(WebBrowserNavigationEvent arg0) {
lastTime = new Date().getTime();
L.info("___________ locationChanged");
// 判断当前页面等级
String locationURL = arg0.getNewResourceLocation();
int index = locationURL.indexOf("pageFlag=");
if (index != -1) {
pageFlag = Integer.parseInt(locationURL.substring(index + 9, index + 10));
} else {
pageFlag = 1;
}
System.out.println("____________________ pageFlag:" + pageFlag);
// 判断下载文件进行打印
index = locationURL.indexOf("fileName=");
System.out.println("____________________ file Index:" + index);
if (index != -1) {
String fs = locationURL.substring(index + 9);
L.info("______________________ fileName = " + fs);
String fns = fs.split(",");
try {
List《File》 flist = downNetFile(Arrays.asList(fns));
doPrintDoc(flist);
} catch (IOException e) {
e.printStackTrace();
}
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
webBrowser.setVisible(false);
webBrowser.setVisible(true);
webBrowser.updateUI();
webBrowser.repaint();
panel.updateUI();
panel.repaint();
panel.validate();
}
});
}
@Override
public void locationChangeCanceled(WebBrowserNavigationEvent arg0) {
lastTime = new Date().getTime();
L.info("___________ locationChangeCanceled");
}
@Override
public void loadingProgressChanged(WebBrowserEvent arg0) {
lastTime = new Date().getTime();
L.info("___________ loadingProgressChanged");
}
@Override
public void commandReceived(WebBrowserCommandEvent arg0) {
lastTime = new Date().getTime();
L.info("___________ commandReceived");
}
});
lbl.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent arg0) {
}
@Override
public void mousePressed(MouseEvent arg0) {
}
@Override
public void mouseExited(MouseEvent arg0) {
}
@Override
public void mouseEntered(MouseEvent arg0) {
}
@Override
public void mouseClicked(MouseEvent arg0) {
change(2);
}
});
}
如何在Java 利用swing组件编写杨辉三角形并用线程实现动态演示
import java.util.*;
import javax.swing.JOptionPane;
public class yhs {
public static void main(String args) {
String input;
input = JOptionPane.showInputDialog(null, "输入一个数", "杨辉三角", JOptionPane.QUESTION_MESSAGE);
int m = Integer.parseInt(input);
int i;
int TriangleYH;
TriangleYH = new int;
System.out.println("\t\t____Triangle of Yanghui____");
for (i = 0; i 《 m; i++)
for (int j = 0; j 《= i; j++)
if (i == j || j == 0)
TriangleYH = 1;
else
TriangleYH;
for (i = 0; i 《 m; i++) {
for (int j = 0; j 《= i; j++) {
if (j == 0)
System.out.print("\t\t");
System.out.print(TriangleYH + "\t");
}
System.out.println("");
}
}
}

更多文章:
全球新冠肺炎疫情背景下航运发展(盐田港复苏日志:半年历劫从“低谷”到“爆仓” 疫情之后巨轮如何越洋航行)
2026年9月7日 17:10
matlab求解带字母参数方程组(我想matlab求一个关于x,y的方程组 ab c d f e h m n 都是参数)
2026年9月7日 16:30
oracle中的循环语句(下面哪个不是oracle程序设计中的循环语句 a for)
2026年9月7日 15:30
电脑里2个系统怎么删除一个(电脑开机显示有两个系统,如何删除一个)
2026年9月7日 12:20
scrollthrough意思(“scroll”是什么意思)
2026年9月7日 08:00
怎么激活keygen(注册机如何激活cad2008一个简单激活cad2008的方法)
2026年9月7日 06:30
vba编写excel插件(excel vba中能否动态创建控件)
2026年9月7日 04:40





