對話框代碼java java對話框分為______和_______兩種
java中程序輸入輸出以對話框的形式表現(xiàn)怎么做?
!doctypehtml
html
head
metacharset="UTF-8"
titleDocument/title
/head
body
buttononclick="mal()"第一種:alert/button
buttononclick="mpro()"第二種:prompt/button
buttononclick="mcon()"第三種:confirm/button
script
functionmal(){
alert('這是一個普通的提示框');
}
functionmpro(){
varval=prompt('這是一個可輸入的提示框','這個參數(shù)為輸入框默認(rèn)值,可以不填哦');
//prompt會把輸入框的值返回給你
}
functionmcon(){
varboo=confirm('這是一個可選擇的提示框,3種提示方式,學(xué)會了嗎?')
//confirm會返回你選擇的選項(xiàng),然后可以依據(jù)選擇執(zhí)行邏輯
if(boo){
alert('學(xué)會了,真聰明');
}else{
alert('再來一遍吧')
}
}
/script
/body
/html
急需一個java編程實(shí)現(xiàn)的簡單聊天窗口代碼
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java點(diǎn)虐.*;
import java.io.*;
public class ClientDemo01 {
public static void main(String[] args){
JFrame f=new JFrame("AA");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JTextArea ta=new JTextArea(15,30);
ta.setEditable(false); //文本域只讀
JScrollPane sp=new JScrollPane(ta); //滾動窗格
JTextField tf=new JTextField(20);
JButton b=new JButton("發(fā)送");
p1.add(sp);
p2.add(tf);
p2.add(b);
f.add(p1,"Center");
f.add(p2,"South");
f.setBounds(300,300,360,300);
f.setVisible(true);
f.setResizable(false);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Socket socket=null;
BufferedInputStream bis=null;
BufferedOutputStream bos=null;
try{
socket=new Socket("192.168.0.4",5000);
bis=new BufferedInputStream(socket.getInputStream());
bos=new BufferedOutputStream(socket.getOutputStream());
MyThread01 mt=new MyThread01(bis,ta);
mt.start();
}catch(Exception e){
e.printStackTrace();
}
b.addActionListener(new ButtonActionListener01(tf,ta,bos));
}
}
class ButtonActionListener01 implements ActionListener{
JTextField tf;
JTextArea ta;
BufferedOutputStream bos;
public ButtonActionListener01(JTextField tf,JTextArea ta,BufferedOutputStream bos){
this.tf=tf;
this.ta=ta;
this.bos=bos;
}
public void actionPerformed(ActionEvent e){
String message=tf.getText();
if(!message.equals("")){
tf.setText(""); //清空文本框
ta.append("AA:"+message+"\n"); //添加到文本域并換行
try{
bos.write(message.getBytes());
bos.flush();
}catch(Exception ex){
System.out.println("發(fā)送失敗");
}
}
}
}
class MyThread01 extends Thread{
BufferedInputStream bis;
JTextArea ta;
public MyThread01(BufferedInputStream bis,JTextArea ta){
this.bis=bis;
this.ta=ta;
}
public void run(){
try{
while(true){
byte[] b=new byte[100];
int length=bis.read(b);
String message=new String(b,0,length);
ta.append("BB:"+message+"\n");
}
}catch(Exception e){
e.printStackTrace();
}
}
} import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java點(diǎn)虐.*;
import java.io.*;
public class ServerDemo01{
public static void main(String[] args){
JFrame f=new JFrame("BB");
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JTextArea ta=new JTextArea(12,30); //文本域,第一個參數(shù)為行數(shù),第二個參數(shù)為列數(shù)
ta.setEditable(false); //文本域只讀
JScrollPane sp=new JScrollPane(ta); //滾動窗格
JTextField tf=new JTextField(20);
JButton b=new JButton("發(fā)送");
p1.add(sp);
p2.add(tf);
p2.add(b);
f.add(p1,"Center");
f.add(p2,"South");
f.setBounds(300,300,360,300);
f.setVisible(true);
f.setResizable(false);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ServerSocket server=null;
Socket socket=null;
BufferedInputStream bis=null;
BufferedOutputStream bos=null;
try{
server=new ServerSocket(5000);
//ta.append("等待AA連接...\n");
socket=server.accept();
//ta.append("AA已連接\n");
bis=new BufferedInputStream(socket.getInputStream());
bos=new BufferedOutputStream(socket.getOutputStream());
MyThread1 mt=new MyThread1(bis,ta);
mt.start();
}catch(Exception e){
e.printStackTrace();
}
b.addActionListener(new ButtonActionListener1(tf,ta,bos));
}
}
class ButtonActionListener1 implements ActionListener{
JTextField tf;
JTextArea ta;
BufferedOutputStream bos;
public ButtonActionListener1(JTextField tf,JTextArea ta,BufferedOutputStream bos){
this.tf=tf;
this.ta=ta;
this.bos=bos;
}
public void actionPerformed(ActionEvent e){
String message=tf.getText(); //獲取文本框中的內(nèi)容
if(!message.equals("")){
tf.setText(""); //清空文本框
ta.append("BB:"+message+"\n"); //添加到文本域并換行
try{
bos.write(message.getBytes());
bos.flush();
}catch(Exception ex){
System.out.println("發(fā)送失??!");
}
}
}
}
class MyThread1 extends Thread{
BufferedInputStream bis;
JTextArea ta;
public MyThread1(BufferedInputStream bis,JTextArea ta){
this.bis=bis;
this.ta=ta;
}
public void run(){
try{
while(true){
byte[] b=new byte[100];
int length=bis.read(b);
String message=new String(b,0,length);
ta.append("AA:"+message+"\n");
}
}catch(Exception e){
e.printStackTrace();
}
}
}
java中經(jīng)過if語句判斷后想彈出提示對話框 如何寫代碼?要求是(若用戶名或密碼為空(包括空格字符)則提示
if(true){
out.println("scriptalert('彈出來了');/script");
}
// 上面這個是寫在JSP 頁面上的.
"要求是(若用戶名或密碼為空(包括空格字符)則提示"
你的意思是不是你在做登陸的時(shí)候要求用戶輸入用戶名和密碼? 而且不能為空?
如果是這樣的話,你可以在 提交 按鈕上加一句 onclick ='checkinfo()' .調(diào)用一個 JS來進(jìn)行判定.
JS可以寫成...
if(document.getElementByID("用戶名").value==null || document.getElementByID("用戶名").value=="")
{
alert("請輸入用戶名");
retrun false ;
}else if(document.getElementByID("密碼").value==null || document.getElementByID("密碼").value=="")
{
alert("請輸入密碼");
retrun false ;
}else {
return true ;
}
這樣的話,在你點(diǎn)提交的時(shí)候,會先進(jìn)行JS的驗(yàn)證, 如果有其中一項(xiàng)沒有填寫則回彈出對應(yīng)的提示框,并返回false.表單提交不了.......否則返回一個真值, 這個時(shí)候你的 表單就能順利提交了....
上一篇:java堆的基本代碼 java 堆的結(jié)構(gòu)
欄 目:Java編程
下一篇:沒有了
本文標(biāo)題:對話框代碼java java對話框分為______和_______兩種
本文地址:http://www.jygsgssxh.com/a1/Javabiancheng/17335.html
您可能感興趣的文章
- 04-09java堆的基本代碼 java 堆的結(jié)構(gòu)
 - 04-09java計(jì)時(shí)開關(guān)代碼 java計(jì)時(shí)程序
 - 04-09java代碼重構(gòu)優(yōu)化經(jīng)驗(yàn) java代碼重構(gòu)的思路
 - 04-09java貸款利率代碼 java利率是什么數(shù)據(jù)類型
 - 04-09安卓輔助java代碼 安卓輔助用什么開發(fā)
 - 04-09俄羅斯方法java源代碼 java編寫俄羅斯方塊代碼
 - 04-07java入門小代碼 java簡單的代碼
 - 04-07繪制圖像就java代碼 java繪制圖形代碼
 - 04-07java代碼異步 java異步處理方法
 - 04-07java修改運(yùn)行中的代碼 java代碼在哪里修改
 


閱讀排行
本欄相關(guān)
- 04-09對話框代碼java java對話框分為______和
 - 04-09java堆的基本代碼 java 堆的結(jié)構(gòu)
 - 04-09java計(jì)時(shí)開關(guān)代碼 java計(jì)時(shí)程序
 - 04-09java代碼重構(gòu)優(yōu)化經(jīng)驗(yàn) java代碼重構(gòu)的
 - 04-09java貸款利率代碼 java利率是什么數(shù)據(jù)
 - 04-09安卓輔助java代碼 安卓輔助用什么開發(fā)
 - 04-09俄羅斯方法java源代碼 java編寫俄羅斯
 - 04-07java入門小代碼 java簡單的代碼
 - 04-07繪制圖像就java代碼 java繪制圖形代碼
 - 04-07java代碼異步 java異步處理方法
 
隨機(jī)閱讀
- 01-11Laravel5.1 框架模型多態(tài)關(guān)聯(lián)用法實(shí)例分
 - 01-10ps命令輸出進(jìn)程狀態(tài)S+的含義解析
 - 01-10JavaScript中的相等操作符使用詳解
 - 01-10C,C++中常用的操作字符串的函數(shù)
 - 01-10C#使用ILGenerator動態(tài)生成函數(shù)的簡單代
 - 08-05織夢首頁和列表頁動態(tài)調(diào)用點(diǎn)擊次數(shù)
 - 08-05dede頻道頁首頁統(tǒng)計(jì)下級欄目文章數(shù)的
 - 01-10C#中用foreach語句遍歷數(shù)組及將數(shù)組作
 - 01-10可以從一臺遠(yuǎn)程服務(wù)器運(yùn)行 SP2 安裝程
 - 01-10用VBS修改(設(shè)置)系統(tǒng)時(shí)間和日期的
 


