网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java的弹出页面代码 java页面弹窗

JAVA中打开新页面代码

/**

创新互联公司IDC提供业务:重庆服务器托管,成都服务器租用,重庆服务器托管,重庆服务器租用等四川省内主机托管与主机租用业务;数据中心含:双线机房,BGP机房,电信机房,移动机房,联通机房。

* 打开打印窗口

* 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弹出新窗口

定义一个按钮的OnClick事件

里面用写方法调用弹出窗口

代码

import java.awt.*;

import javax.swing.*;

import java.awt.Rectangle;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class Frame1 extends JFrame

{

private JButton jButton1=new JButton();

public Frame1 ()

{

try {

jbInit();

}

catch(Exception exception) {

exception.printStackTrace();

}

this.setVisible(true);

}

private void jbInit () throws Exception

{

this.setBounds(300,180,400,300);

getContentPane().setLayout(null);

jButton1.setBounds(new Rectangle(127, 120, 139, 36));

jButton1.setMnemonic('C');

jButton1.setText("点我(C)");

jButton1.addActionListener(new ActionListener()

{

public void actionPerformed (ActionEvent e)

{

jButton1_actionPerformed(e);

}

});

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.getContentPane().add(jButton1);

}

public static void main (String[] args)

{

Frame1 frame1=new Frame1();

}

public void jButton1_actionPerformed (ActionEvent e)

{

this.setVisible(false);

JFrame jf1=new JFrame("子窗口");

jf1.setBounds(100,50,800,600);

jf1.setDefaultCloseOperation(jf1.EXIT_ON_CLOSE);

jf1.setVisible(true);

}

}

JAVA的弹窗怎么做?

JAVA弹窗,有下面常见的2种方法实现:

通过JDialog(模式窗口) 类来实现.里面的写法类似JFrame

重点方法提示: setModal(true);

//当设置为true表示,如果不关闭这个弹窗,那么主界面的其他组件都无法操作,该弹窗置于其他窗口的前面

//当设置为false表示,可以绕开本弹窗,对主界面的其他组件进行操作

优点: 功能强大,  扩展性强

缺点: 代码量大.

示例图

通过JOptionPane(提示框) 来实现

效果图如下

优点: 代码量少,简单,方便, 普通场景已经够用

缺点: 扩展性不够, 复杂逻辑难以实现.

下面写一个具体案例

场景:当用于对文本域的文字,进行操作后,那么退出时,提示用户, 是否要保存已经更改后的内容.  如果用户没有修改内容,那么不用提示

重点代码

addDocumentListener--用于实现对文本内容发生改变时进行响应

addWindowListener---用于实现对窗口进行操作时进行响应

完整代码如下

import java.awt.Font;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

public class JDDemo extends JFrame implements DocumentListener,WindowListener{

JTextArea jta;

boolean flag;

public JDDemo() {

jta = new JTextArea();//文本域

jta.setText("床前明月光");//文本域的文字--可以通过IO加载txt文档的文字

jta.setFont(new Font("宋体",Font.BOLD, 20));//文本域的字体

jta.setLineWrap(true);//设置自动换行

jta.getDocument().addDocumentListener(this);//添加文档变化事件的响应.比如修改,删除等

JScrollPane jsp = new JScrollPane(jta);//滚动面板(当文字太多时,显示滚动条)

add(jsp);

setTitle("主窗口");//标题

setSize(300, 260);//大小

setLocationRelativeTo(null);//居中

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//点击窗口的关闭按钮时,执行windowClosing的代码

addWindowListener(this);

setVisible(true);//窗口可见

}

public static void main(String[] args) {

new JDDemo();

}

//实现WindowListener接口,需要重写下面的6个方法, windowClosing专门处理关闭时的方法

public void windowOpened(WindowEvent e) {

}

public void windowClosing(WindowEvent e) {

if(flag){

int n = JOptionPane.showConfirmDialog(null, "已经更改了内容,需要保存后再退出吗?", "提示",JOptionPane.YES_NO_OPTION);

//n等于-1表示关闭了弹出的对话框等情况的默认值

//n等于0(JOptionPane.YES_OPTION)表示选择了Yes

//n等于1(JOptionPane.NO_OPTION)表示选择了No

if(n==JOptionPane.YES_OPTION){

//把文字保存到文件的代码省略...

System.out.println("正在使用IO进行保存..ing");

closeFrame();//关闭窗口并退出

}else if(n==JOptionPane.NO_OPTION){

System.out.println("放弃保存修改.马上退出");

closeFrame();

}

}else{

closeFrame();

}

}

public void windowClosed(WindowEvent e) {

}

public void windowIconified(WindowEvent e) {

}

public void windowDeiconified(WindowEvent e) {

}

public void windowActivated(WindowEvent e) {

}

public void windowDeactivated(WindowEvent e) {

}

//文档事件,有下面三个,如果触发其中一个,都可以认为修改了文档,所以需要在退出时进行提示,是否保存

public void insertUpdate(DocumentEvent e) {//插入

flag=true;

}

public void removeUpdate(DocumentEvent e) {//删除

flag=true;

}

public void changedUpdate(DocumentEvent e) {//改变

flag=true;

}

//关闭窗口的方法

public void closeFrame(){

this.setVisible(false);//窗口不可见

this.dispose();//窗口销毁

System.exit(0);//JVM虚拟机退出

}

}

运行效果图:

如何用Java实现弹出窗口 非常感谢!(最好给个实例)

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

public class MyWindow extends JFrame{

public JFrame newFrame=new JFrame("弹出的新窗口");

public JFrame frame=null;

public JButton button=new JButton("弹出新窗口");

MyWindow(){

super("测试");

frame=this;

add(button);

button.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)

{

newFrame.setSize(100, 100);

newFrame.setVisible(true);

}

});;

setSize(200,200);

this.setVisible(true);

}

public static void main(String[] args){

new MyWindow();

}

}


本文名称:java的弹出页面代码 java页面弹窗
当前路径:http://bjjierui.cn/article/dopgpeg.html

其他资讯