java代码打开新页面,java打开新窗口

java下面这段程序怎么改才能实现打开新页面时该页面关闭?

得在新页面中得到原来页面的句柄,并将其close掉。

创新互联公司是专业的安新网站建设公司,安新接单;提供网站设计、成都网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行安新网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

一种方法是,创建新页面时,在新页面中加入一个属性,保存原页面的引用,并且在show之后的函数中,关闭原来的页面。

如何在java程序中,当点击一个按钮后,关闭当前窗口,开启一个新的窗口?

JButton btn=new JButton(new AbstractAction("关闭并打开") {      @Override   public void actionPerformed(ActionEvent e) {      oldFrame.dispose();// 关闭并销毁,无需销毁可采用oldFrame.setVisible(false);      newFrame.setVisible(true);// 打开新窗口   }});

import javax.swing.*;

import java.awt.Rectangle;

import java.awt.event.*;

public class Swing7 extends JFrame implements ActionListener {

JButton jb = new JButton();

public Swing7() {

this.setTitle("Java——");

jb.setText("确定");

jb.setMnemonic('a');

this.add(jb);

this.setBounds(200, 300, 250, 300);

ctionListener就是Swing7实例。

}

public void actionPerformed(ActionEvent e) {// 实现ActionListener接口的actionPerformed接口。

JFrame frame = new JFrame("新窗口");//构造一个新的JFrame,作为新窗口。

frame.setBounds(// 让新窗口与Swing7窗口示例错开50像素。

new Rectangle(

(int) this.getBounds().getX() + 50,

(int) this.getBounds().getY() + 50,

(int) this.getBounds().getWidth(),

(int) this.getBounds().getHeight()

)

);

JLabel jl = new JLabel();// 注意类名别写错了。

frame.getContentPane().add(jl);

jl.setText("这是新窗口");

jl.setVerticalAlignment(JLabel.CENTER);

jl.setHorizontalAlignment(JLabel.CENTER);// 注意方法名别写错了。

frame.setVisible(true);

}

public static void main(String args[]) {

Swing7 s = new Swing7();

}

}

JAVA类如何打开网页?

JAVA中的类是具备某些共同特征的实体的集合,它是一种抽象的概念,用程序设计的语言来说,类是一种抽象的数据类型,它是对所具有相同特征实体的抽象。所谓对象就是真实世界中的实体,对象与实体是一一对应的,也就是说现实世界中每一个实体都是一个对象,对象是一种具体的概念。JAVA类打开网页有以下方法:

1、java.net.URI uri = new java.net.URI("");

java.awt.Desktop.getDesktop().browse(uri);

2、Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler ");

这两种方法是可以打开,不过只能在服务端打开,如果有另一台机器访问我的机器,执行上边的程序后,也会在我本机显示baidu的页面。

3、如果是让他自动打开可以用robot类模拟鼠标单击右键双击等动作,还可以模拟输入。

4、如果要在网页做复杂操作可以用swt做一个浏览器,可以控制他执行网站里的脚本,这个比较难点。

JAVA中打开新页面代码

/**

* 打开打印窗口

* url:链接页面或action动作

* Banglu

*/

function printWindow(url){

var sURL = url;

var sFeatures = "toolbar=no, menubar=no, scrollbars=no,resizable=yes, "

+ "location=no, status=no, titlebar=no, width=800, height=600, top=100, left=100";

window.open(sURL,'notoolbar',sFeatures);

}function exportWindow(url){

var sURL = url;

var sFeatures = "toolbar=no, menubar=no, scrollbars=no,resizable=yes, "

+ "location=no, status=no, titlebar=no, width=800, height=600, top=50, left=50";

var objwin=window.open(sURL,'export'+randomNum(),sFeatures);

objwin.close();

}

/**

* 打开模态窗口

* url:链接页面或action动作

* width:打开模态窗口的宽度

* height:打开模态窗口的高度

* 注意:打开模态窗口的页面中要在head后面加上

* meta http-equiv="Pragma" content="no-cache":禁止模态窗口缓存

* base target="_self"/:模态窗口中的表单在本窗口中提交

* a onClick='window.location = "view-source:" + window.location.href'b源文件/b/a 可以查看模态窗口的源文件

* Banglu

*/

function modalWindow(url, width, height){

var sURL = url;

var sFeatures = "dialogWidth:" + width + "px; dialogHeight:" + height + "px; "

+ "help:no; scroll:yes; center:yes; status:no;resizable:yes";

window.showModalDialog(sURL, window, sFeatures);

}/**

* 打开普通窗口

* url:链接页面或action动作

* width:宽度

* height:高度

* Banglu

*/

function openWindow(url, width, height){

var sURL=url;

var sFeatures = "scrollbars=yes, status=yes, resizable=yes,"

+ "toolbar=yes, menubar=yes, location=yes, titlebar=yes"

if(width!=null){

sFeatures+=", width="+width;

}

if(height!=null){

sFeatures+=", height="+height;

}

window.open(sURL, 'open'+randomNum(), sFeatures);

}/**

* 打开窗口

* url:链接页面或action动作

* width:宽度

* height:高度

Banglu

*/

function openNoBarWindow(url, width, height){

var sURL=url;

var sFeatures = "scrollbars=no, status=no, resizable=no,"

+ "toolbar=no, menubar=no, location=no, titlebar=no"

if(width!=null){

sFeatures+=", width="+width;

sFeatures+=", left="+(screen.width-width)/2;

}

if(height!=null){

sFeatures+=", height="+height;

sFeatures+=", top="+(screen.height-height-100)/2;

}

window.open(sURL, 'openNoBar'+randomNum(), sFeatures);

}

/**

* 打开全屏窗口

* url:链接页面或action动作

* Banglu

*/

function openFullWindow(url){

var sURL=url;

var sFeatures = "toolbar=no, menubar=no, scrollbars=no, resizable=yes, "

+ "location=no, status=no, titlebar=no, width="+(screen.width-10)+", "

+ "height="+(screen.height-60)+", top=0, left=0";

window.open(sURL, 'full'+randomNum(), sFeatures);

}/**

* 打开主窗口

* url:链接页面或action动作

* Banglu

*/

function openMainWindow(url){

var sURL=url;

var sFeatures = "toolbar=no, menubar=no, scrollbars=no, resizable=yes, "

+ "location=no, status=no,titlebar=no, width="+(screen.width-10)+", "

+ "height="+(screen.height-60)+", top=0, left=0";

window.open(sURL, 'main', sFeatures);

}

/**

* 设置链接

* url:连接的jsp页面或action动作

* Banglu

*/

function link(url, frameID){

if(frameID==null){

window.location.href = url;

}

else{

window.frames[frameID].location = url

}

}/**

* 回车代替tab

* Banglu

*/

function handleKey(){

var gk = window.event.keyCode;

if (gk==13) {

if(window.event.srcElement.tagName!='TEXTAREA'){

window.event.keyCode=9;

return;

}

}

}/**

* 全屏显示

* Banglu

*/

function fullScreen(){

window.dialogHeight=window.screen.availHeight;

window.dialogWidth=window.screen.availWidth;

}

function Resize_dialog(t,l,w,h) {

window.dialogTop = t+"px";

window.dialogLeft = l+"px";

window.dialogHeight = h+"px";

window.dialogWidth = w+"px";

}

Java编程中,要如何实现“打开一个新页面的同时,关闭原先的页面。”

你说的是web吗?

除了直接target="_blank",还在jsp页面上打开个有页面就可以了:有两中形式的页面

有模页面:window.showModalDialog(url, window, "Status:YES;dialogWidth:200px;dialogHeight:100px;help:no;scroll:no")

没模页面:window.open(url,'newWin','modal=yes,width=560,height=420,resizable=no,scrollbars=no');

a、b页面:自己写哦!其中在a页面里面写个连接就可以了

有模页面:a href="javascript:window.showModalDialog("/b页面的地址(url)", window, "Status:YES;dialogWidth:200px;dialogHeight:100px;help:no;scroll:no");

打开b页面/a

没模页面window.open(("/b页面的地址(url)",'newWin','modal=yes,width=560,height=420,resizable=no,scrollbars=no');

打开b页面/a

java代码实现弹出新窗口,并把数据传给新窗口,类似预览的效果

想要达到你说的效果,用Struts不行的,要不然不会出现俩页面的。可以用js库的window.open来做,参数的传递可以用json。这样会弹出一个自定义的新窗口,不用走什么请求。


本文题目:java代码打开新页面,java打开新窗口
文章网址:http://pwwzsj.com/article/hcshos.html