新聞中心
JAVA中打開新頁面代碼
/**
專注于為中小企業(yè)提供網(wǎng)站設(shè)計制作、成都網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)上海免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
* 打開打印窗口
* 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();
}
/**
* 打開模態(tài)窗口
* url:鏈接頁面或action動作
* width:打開模態(tài)窗口的寬度
* height:打開模態(tài)窗口的高度
* 注意:打開模態(tài)窗口的頁面中要在head后面加上
* meta http-equiv="Pragma" content="no-cache":禁止模態(tài)窗口緩存
* base target="_self"/:模態(tài)窗口中的表單在本窗口中提交
* a onClick='window.location = "view-source:" + window.location.href'b源文件/b/a 可以查看模態(tài)窗口的源文件
* 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);
}
/**
* 設(shè)置鏈接
* 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做好的登陸界面,當(dāng)?shù)顷懗晒筇D(zhuǎn)到下個頁面的代碼是什么?
用java做好的登陸界面,當(dāng)?shù)顷懗晒筇D(zhuǎn)到下個頁面的代碼如下:
如果登陸驗證是在jsp中,那么跳轉(zhuǎn)可以寫成
1.response.sendRedirct("跳轉(zhuǎn)到頁面");
2.jsp:forward page="跳轉(zhuǎn)頁面"/
3.response.setHeader("Location","");
如果是登陸驗證是在servlet中,那么中轉(zhuǎn)可以寫成
1.response.sendRedirect("/a.jsp");
2.RequestDispatcher dispatcher = request.getRequestDispatcher("/a.jsp");
dispatcher .forward(request, response);
也可以使用js代碼實現(xiàn):
script
function validate(){
window.location.href="/index.jsp";
}
/script
登陸界面的java代碼怎么寫?
概述
具體框架使用jframe,文本框組件:JTextField;密碼框組件:JPasswordField;標(biāo)簽組件:JLabel;復(fù)選框組件:JCheckBox;單選框組件:JRadioButton;按鈕組件JButton。
登錄界面:
代碼實例
import javax.swing.*;
import java.awt.*; ? //導(dǎo)入必要的包
public class denglu extends JFrame{
JTextField jTextField ;//定義文本框組件
JPasswordField jPasswordField;//定義密碼框組件
JLabel jLabel1,jLabel2;
JPanel jp1,jp2,jp3;
JButton jb1,jb2; //創(chuàng)建按鈕
public denglu(){
jTextField = new JTextField(12);
jPasswordField = new JPasswordField(13);
jLabel1 = new JLabel("用戶名");
jLabel2 = new JLabel("密碼");
jb1 = new JButton("確認(rèn)");
jb2 = new JButton("取消");
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
//設(shè)置布局
this.setLayout(new GridLayout(3,1));
jp1.add(jLabel1);
jp1.add(jTextField);//第一塊面板添加用戶名和文本框
jp2.add(jLabel2);
jp2.add(jPasswordField);//第二塊面板添加密碼和密碼輸入框
jp3.add(jb1);
jp3.add(jb2); //第三塊面板添加確認(rèn)和取消
// ? ? ? ?jp3.setLayout(new FlowLayout()); ?//因為JPanel默認(rèn)布局方式為FlowLayout,所以可以注銷這段代碼.
this.add(jp1);
this.add(jp2);
this.add(jp3); ?//將三塊面板添加到登陸框上面
//設(shè)置顯示
this.setSize(300, 200);
//this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.setTitle("登陸");
}
public static void main(String[] args){
new denglu();
}
}
拓展內(nèi)容
java swing包
Swing 是一個為Java設(shè)計的GUI工具包。
Swing是JAVA基礎(chǔ)類的一部分。
Swing包括了圖形用戶界面(GUI)器件如:文本框,按鈕,分隔窗格和表。
Swing提供許多比AWT更好的屏幕顯示元素。它們用純Java寫成,所以同Java本身一樣可以跨平臺運行,這一點不像AWT。它們是JFC的一部分。它們支持可更換的面板和主題(各種操作系統(tǒng)默認(rèn)的特有主題),然而不是真的使用原生平臺提供的設(shè)備,而是僅僅在表面上模仿它們。這意味著你可以在任意平臺上使用JAVA支持的任意面板。輕量級組件的缺點則是執(zhí)行速度較慢,優(yōu)點就是可以在所有平臺上采用統(tǒng)一的行為。
概念解析:
JFrame?– java的GUI程序的基本思路是以JFrame為基礎(chǔ),它是屏幕上window的對象,能夠最大化、最小化、關(guān)閉。
JPanel?– Java圖形用戶界面(GUI)工具包swing中的面板容器類,包含在javax.swing 包中,可以進(jìn)行嵌套,功能是對窗體中具有相同邏輯功能的組件進(jìn)行組合,是一種輕量級容器,可以加入到JFrame窗體中。。
JLabel?– JLabel 對象可以顯示文本、圖像或同時顯示二者。可以通過設(shè)置垂直和水平對齊方式,指定標(biāo)簽顯示區(qū)中標(biāo)簽內(nèi)容在何處對齊。默認(rèn)情況下,標(biāo)簽在其顯示區(qū)內(nèi)垂直居中對齊。默認(rèn)情況下,只顯示文本的標(biāo)簽是開始邊對齊;而只顯示圖像的標(biāo)簽則水平居中對齊。
JTextField?–一個輕量級組件,它允許編輯單行文本。
JPasswordField?– 允許我們輸入了一行字像輸入框,但隱藏星號(*) 或點創(chuàng)建密碼(密碼)
JButton?– JButton 類的實例。用于創(chuàng)建按鈕類似實例中的 "Login"。
求JAVA簡易計算機(jī)源代碼
試試這個
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class SZJSQ extends JApplet implements ActionListener
{
boolean i=true;
private JButton num0=new JButton("0");
private JButton num1=new JButton("1");
private JButton num2=new JButton("2");
private JButton num3=new JButton("3");
private JButton num4=new JButton("4");
private JButton num5=new JButton("5");
private JButton num6=new JButton("6");
private JButton num7=new JButton("7");
private JButton num8=new JButton("8");
private JButton num9=new JButton("9");
private JButton zuok=new JButton("(");
private JButton youk=new JButton(")");
private JButton dian=new JButton(".");
private JButton NULL=new JButton("N");
private JButton plu=new JButton("+");
private JButton min=new JButton("-");
private JButton mul=new JButton("x");
private JButton div=new JButton("/");
private JButton equ=new JButton("=");
private JButton cle=new JButton("C");//清除
private JTextField space=new JTextField(30);
public void init()
{
JPanel text=new JPanel();
text.setLayout(new FlowLayout());
text.add(space);
JPanel buttons=new JPanel();
buttons.setLayout(new GridLayout(5,4));
buttons.add(num9);
buttons.add(num8);
buttons.add(num7);
buttons.add(plu);
buttons.add(num6);
buttons.add(num5);
buttons.add(num4);
buttons.add(min);
buttons.add(num3);
buttons.add(num2);
buttons.add(num1);
buttons.add(mul);
buttons.add(num0);
buttons.add(cle);
buttons.add(equ);
buttons.add(div);
buttons.add(zuok);
buttons.add(youk);
buttons.add(dian);
buttons.add(NULL);
(num9).addActionListener(this);
(num8).addActionListener(this);
(num7).addActionListener(this);
(num6).addActionListener(this);
(num5).addActionListener(this);
(num4).addActionListener(this);
(num3).addActionListener(this);
(num2).addActionListener(this);
(num1).addActionListener(this);
(num0).addActionListener(this);
(plu).addActionListener(this);
(min).addActionListener(this);
(mul).addActionListener(this);
(div).addActionListener(this);
(equ).addActionListener(this);
(cle).addActionListener(this);
(zuok).addActionListener(this);
(youk).addActionListener(this);
(dian).addActionListener(this);
setLayout(new BorderLayout());
add("North",text);
add("South",buttons);
space.setText("0");
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==num9)
{
if(i==true)
{
space.setText("9");
i=false;
}
else space.setText(space.getText()+'9');
}
if(e.getSource()==num8)
{
if(i==true)
{
space.setText("8");
i=false;
}
else space.setText(space.getText()+'8');
}
if(e.getSource()==num7)
{
if(i==true)
{
space.setText("7");
i=false;
}
else space.setText(space.getText()+'7');
}
if(e.getSource()==num6)
{
if(i==true)
{
space.setText("6");
i=false;
}
else space.setText(space.getText()+'6');
}
if(e.getSource()==num5)
{
if(i==true)
{
space.setText("5");
i=false;
}
else space.setText(space.getText()+'5');
}
if(e.getSource()==num4)
{
if(i==true)
{
space.setText("4");
i=false;
}
else space.setText(space.getText()+'4');
}
if(e.getSource()==num3)
{
if(i==true)
{
space.setText("3");
i=false;
}
else space.setText(space.getText()+'3');
}
if(e.getSource()==num2)
{
if(i==true)
{
space.setText("2");
i=false;
}
else space.setText(space.getText()+'2');
}
if(e.getSource()==num1)
{
if(i==true)
{
space.setText("1");
i=false;
}
else space.setText(space.getText()+'1');
}
if(e.getSource()==num0)
{
if(i==true)
{
space.setText("0");
i=false;
}
else space.setText(space.getText()+'0');
}
if(e.getSource()==zuok)
{
if(i==true)
{
space.setText("(");
i=false;
}
else space.setText(space.getText()+'(');
} if(e.getSource()==youk)
{
if(i==false)
space.setText(space.getText()+')');
}
if(e.getSource()==dian)
{
if(i==false)
space.setText(space.getText()+'.');
}
if(e.getSource()==plu)
{
space.setText(space.getText()+'+');
i=false;
}
if(e.getSource()==min)
{
space.setText(space.getText()+'-');
i=false;
}
if(e.getSource()==mul)
{
space.setText(space.getText()+'*');
i=false;
}
if(e.getSource()==div)
{
space.setText(space.getText()+'/');
i=false;
}
if(e.getSource()==equ)
{
space.setText(String.valueOf(Calculator(space.getText())));
i=true;
}
if(e.getSource()==cle)
{
space.setText("0");
i=true;
}
}
public double Calculator(String f)//科學(xué)計算
{
int i=0,j=0,k;
char c;
StringBuffer s=new StringBuffer();
s.append(f);
s.append('=');
String formula=s.toString();
char[] anArray;
anArray=new char[50];
StackCharacter mystack=new StackCharacter();
while(formula.charAt(i)!='=')
{
c=formula.charAt(i);
switch(c)
{
case '(': mystack.push(new Character(c));
i++;
break;
case ')':
while(mystack.peek().charValue()!='(')
{
anArray[j++]=mystack.pop().charValue();
}
mystack.pop();
i++;
break;
case '+':
case '-':
while(!mystack.empty()mystack.peek().charValue()!='(')
{
anArray[j++]=mystack.pop().charValue();
}
mystack.push(new Character(c));
i++;
break;
case '*':
case '/':
while(!mystack.empty()(mystack.peek().charValue()=='*'||mystack.peek().charValue()=='/'))
{
anArray[j++]=mystack.pop().charValue();
}
mystack.push(new Character(c));
i++;
break;
case' ': i++;
break;
default: while((c='0'c='9')||c=='.')
{
anArray[j++]=c;
i++;
c=formula.charAt(i);
}
anArray[j++]='#';
break;
}
}
while(!(mystack.empty()))
anArray[j++]=mystack.pop().charValue();
i=0;
int count;
double a,b,d;
StackDouble mystack1 =new StackDouble();
while(ij)
{
c=anArray[i];
switch(c)
{
case '+':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b+a;
mystack1.push(new Double(d));
i++;
break;
case '-':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b-a;
mystack1.push(new Double(d));
i++;
break;
case '*':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
d=b*a;
mystack1.push(new Double(d));
i++;
break;
case '/':
a=mystack1.pop().doubleValue();
b=mystack1.pop().doubleValue();
if(a!=0)
{
d=b/a;
mystack1.push(new Double(d));
i++;
}
else
{
System.out.println("Error!");
}
break;
default:
d=0;count=0;
while((c='0'c='9'))
{
d=10*d+c-'0';
i++;
c=anArray[i];
}
if(c=='.')
{
i++;
c=anArray[i];
while((c='0'c='9'))
{
count++;
d=d+(c-'0')/Math.pow(10,count);
i++;
c=anArray[i];
}
}
if(c=='#')
mystack1.push(new Double(d));
i++;
break;
}
}
return(mystack1.peek().doubleValue());
}
}
分享名稱:java計算機(jī)頁面代碼,java編程網(wǎng)頁
文章位置:http://www.ef60e0e.cn/article/hoeiij.html