導航:首頁 > 編程語言 > java圖形界面彈窗

java圖形界面彈窗

發布時間:2023-05-14 00:38:02

A. java圖形界面問題(採用彈窗報錯)

JOptionPane.showMessageDialog("null","你的輸入不合法!");

這種方法是swing裡面的如果用awt裡面的方法其實是dialogd=newdialog(f,"提示信息「,true)f表示的是這個對話框是哪個窗體錯誤時的彈出對話框,true表示的是如果這個彈出對話框不關閉則不能對frame進行操作,在d裡面再加一個label表示你要提示的信息。給你貼一段代碼

but.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEvente){

Stringtext=tf.getText();

tf.setText("");

Filefile=newFile(text);

if(file.exists()&&file.isDirectory()){//--------->兩種遍歷方法。。。記下來吧都

ta.setText("");

/*String[]names=file.list();

for(Stringname:names){

ta.append(name+" ");

}*/

traverse(file);

}

else{

Stringmsg="您輸入的"+text+"有誤,請重新輸入!";

lab.setText(msg);

d.setVisible(true);

}

}

});

這一塊的else部分就是實現彈窗的代碼

importstaticjava.awt.BorderLayout.NORTH;

importjava.awt.Button;

importjava.awt.Dialog;

importjava.awt.FlowLayout;

importjava.awt.Frame;

importjava.awt.Label;

importjava.awt.Panel;

importjava.awt.TextArea;

importjava.awt.TextField;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjava.awt.event.WindowAdapter;

importjava.awt.event.WindowEvent;

importjava.io.File;

classDemo{

privateFramef;

privateTextAreata;

privateButtonbut;

privateTextFieldtf;

privateDialogd;

privateLabellab;//錯誤操作彈出對話框裡面的文字

privateButtonbt;

privatePanelp;

Demo(){

init();

}//endofDemo

publicvoidinit(){

lab=newLabel();//提示信息,現在還不知道

p=newPanel();

f=newFrame("mywindow");

f.setBounds(300,100,600,500);

f.setLayout(newFlowLayout());

tf=newTextField(60);

but=newButton("轉到");

ta=newTextArea(25,69);

d=newDialog(f,"提示信息",true);

bt=newButton("確定");

d.setBounds(400,200,300,100);

//d.setLayout(newFlowLayout());

d.add(lab,NORTH);

p.setLayout(newFlowLayout());

p.add(bt);

d.add(p);

f.add(tf);

f.add(but);

f.add(ta);

f.setVisible(true);

myEvent();

}//endofinit()

//實現各種監聽事件

publicvoidmyEvent(){

tf.addActionListener(newActionListener(){//按回車實現"轉到"按鈕

publicvoidactionPerformed(ActionEvente){

Stringtext=tf.getText();

tf.setText("");

Filefile=newFile(text);

if(file.exists()&&file.isDirectory()){//--------->兩種遍歷方法。。。記下來吧都

ta.setText("");

/*String[]names=file.list();

for(Stringname:names){

ta.append(name+" ");

}*/

traverse(file);

}

else{

Stringmsg="您輸入的"+text+"有誤,請重新輸入!";

lab.setText(msg);

d.setVisible(true);

}

}

});

//關閉窗口

f.addWindowListener((newWindowAdapter(){

@Override

publicvoidwindowClosing(WindowEvente){

System.exit(1);

}

}));

//隱藏對話框

d.addWindowListener((newWindowAdapter(){

@Override

publicvoidwindowClosing(WindowEvente){

d.setVisible(false);

}

}));

//按確定按鈕隱藏對話框

bt.addActionListener(newActionListener(){

@Override

publicvoidactionPerformed(ActionEvente){

d.setVisible(false);

}

});

//按」轉到「按鈕實現遍歷

but.addActionListener(newActionListener(){

publicvoidactionPerformed(ActionEvente){

Stringtext=tf.getText();

tf.setText("");

Filefile=newFile(text);

if(file.exists()&&file.isDirectory()){//--------->兩種遍歷方法。。。記下來吧都

ta.setText("");

/*String[]names=file.list();

for(Stringname:names){

ta.append(name+" ");

}*/

traverse(file);

}

else{

Stringmsg="您輸入的"+text+"有誤,請重新輸入!";

lab.setText(msg);

d.setVisible(true);

}

}

});

}//endofmyEvent()

publicvoidtraverse(Filefile){//遍歷文件

File[]arr=file.listFiles();//返回一個文件路徑數組

for(inti=0;i<arr.length;i++){

if(arr[i].isFile())

ta.append(arr[i]+" ");

elsetraverse(arr[i]);

}

}//endoftraverse()

}//endofDemo{}

publicclassMain{

publicstaticvoidmain(String[]args){

newDemo();

}

}

實現界面如圖

B. JAVA彈窗如何做

點擊關閉按鈕執行關閉文本文檔窗口之前,先判斷文本文檔中輸入的內容與之前的內容是否相同(要先保存打開文本文檔毀大中的內容),如果不同,就彈出對話框詢問有修改是否蘆臘要保存;如果相陪余滑同就直接關閉文本窗口即可。

C. java怎樣實現彈出窗口

JOptionPane.showMessageDialog()

public static void showMessageDialog(Component parentComponent,
Object message,
String title,
int messageType)
throws HeadlessException調出對話框,它顯示使用由 messageType 參數確定的默認圖標的 message。

參數:
parentComponent - 確定在其中顯示對話框的 Frame;如果為 null 或者 parentComponent 不具有 Frame,則使用默認的 Frame
message - 要顯示的 Object
title - 對話框的標題字元串
messageType - 要顯示的消息類型:ERROR_MESSAGE、INFORMATION_MESSAGE、WARNING_MESSAGE、QUESTION_MESSAGE 或 PLAIN_MESSAGE

D. JAVA的彈窗怎麼做

JAVA彈窗,有下面常見的2種方法實現:

  1. 通過JDialog(模式窗口) 類來實現.裡面的寫法類似JFrame

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

    //當設置為true表示,如果不關閉這個彈窗,那麼主界面的其他組件都無法操作,該彈窗置於其他窗口的前面

    //當設置為false表示,可以繞開本彈窗,對主界面的其他組件進行操作


    優點: 功能強大, 擴展性強

    缺點: 代碼量大.

    示例圖

    E. java如何操作彈出框

    //不知道有沒有理解你的意思;類似一個死循環:下面是點一次出來一個窗口,記錄上次輸入的文字
    //思路就是給個全局變數即可;坐標同理遞增防止覆蓋;
    importjava.awt.FlowLayout;
    importjava.awt.event.ActionEvent;
    importjava.awt.event.ActionListener;

    importjavax.swing.JButton;
    importjavax.swing.JFrame;
    importjavax.swing.JTextField;
    {
    privateJTextFieldjt1;
    privateJButtonbut;
    staticStringstr="";
    staticintx=0,y=0,count=0;
    =1L;
    TestText(){
    //如果第二次開始沒有輸入字就不創建
    if(count>=1&&(str.length()<1)){
    return;
    }
    count++;
    x=100;
    y+=80;
    this.setTitle("第"+count+"個窗口");
    this.setBounds(x,y,200,80);
    this.setLayout(newFlowLayout());
    this.setResizable(false);
    init();
    this.setDefaultCloseOperation(3);
    this.setVisible(true);
    }
    privatevoidinit(){
    jt1=newJTextField(10);
    jt1.setText(str);
    but=newJButton("確定");
    but.addActionListener(newActionListener(){
    @Override
    publicvoidactionPerformed(ActionEvente){
    str=jt1.getText();
    newTestText();
    }
    });
    this.add(jt1);
    this.add(but);
    }
    publicstaticvoidmain(String[]args){
    newTestText();
    }
    }

    F. JAVA 安卓初學,我想點擊一個按鈕彈出一個界面上有一個圖怎麼做

    你是要彈出一個窗體還是只是一個提示?
    button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    //你的代碼專
    }
    });

    如果是提示,最簡單的就屬是Toast.make(this,"",Toast.LENGTH_SHORT).show();
    如果是彈窗,就寫一個dialog,設置dialog.setContentView(view);其中view是你dialog內的布局。button點擊里的代碼就寫dialog.show();需要隱藏dialog的時候調用dialog.dismiss();就行了。
    AlertDialog.Build這個類有自帶的「OK」和「Cancel」按鈕,設置也比較簡單
    還可以用popupwindow等等。

    G. JAVA GUI如何製作彈窗

    繼承JDialog,,JDialog裡面的寫法和JFrame差不多,例如一拍拍個類AboutJFrame extends JDialog
    不同寬賀仔的是:AboutJFrame 需要添加 this.setModal(true);this.setVisible(flag);
    在需要調用該慎汪界面的時候使用 aboutJPanel = new AboutJFrame();
    aboutJPanel.setFlag(true);

    在需要刪掉該界面的時候,在AboutJFrame 類裡面寫上監聽器
    this.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    dispose();
    }
    });

    H. java swing 如何彈出下圖提示框

    JOptionPane.showConfirmDialog (null, "本文檔正在列印。允許要列印嗎?", "友情提示", JOptionPane.YES_NO_OPTION);

    I. 這個JAVA彈窗什麼意思如何解決

    對屬性沒有空中讀寫權斗塵山限。
    看看你的jre\lib\security\java.policy 文件的兄磨內容

    J. 如何在JAVA中實現彈出模式窗口JDialog

    package myclass;

    import javax.swing.JOptionPane;
    import java.awt.*;
    public class MyDialog extends Frame {
    public String showInputDialog(String value){
    //顯示一個要求用戶鍵入 String 的對話框:
    return JOptionPane.showInputDialog(value);
    }
    public void showMessageDialog(String title,String message){
    //顯示一個錯誤對話框,該對話框顯示的 message 為 'alert':
    JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
    }
    public boolean showOptionDialog(){
    //示一個警告對話框,其 options 為 OK、CANCEL,title 為 'Warning',message 為 'Click OK to continue':
    String[] options = { "OK", "CANCEL" };
    int result=JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
    null, options, options[0]);
    if(result==0)
    return true;
    else
    return false;
    }
    public String possibleValues(String[] a){
    //顯示一個要求用戶選擇 String 的對話框:
    //String[] possibleValues = { "First", "Second", "Third" };
    String selectedValue = (String) JOptionPane.showInputDialog(null,
    "Choose one", "Input",
    JOptionPane.INFORMATION_MESSAGE, null,
    a, a[0]);
    return selectedValue;
    }
    }

閱讀全文

與java圖形界面彈窗相關的資料

熱點內容
qq空間66版本下載 瀏覽:908
有一款看美劇的app是什麼 瀏覽:397
前端後端json資料庫 瀏覽:267
vi文件格式linux 瀏覽:963
php如何引用js文件 瀏覽:531
word轉成pdf怎麼設置漸變色背景 瀏覽:655
數控車床車刀如何編程 瀏覽:577
為什麼復制到u盤沒有文件 瀏覽:792
三星怎麼設置文件的打開方式 瀏覽:332
微信怎麼發大容量的文件夾 瀏覽:130
hl線切割編程怎麼旋轉圖形 瀏覽:234
qq頭像露全身 瀏覽:811
力量運動員影響哪些體檢數據 瀏覽:176
金山哪裡有加工中心編程培訓學校 瀏覽:113
壓縮文件正在壓縮怎麼取消 瀏覽:462
excel中添加文件路徑名 瀏覽:16
手機收銀用哪個app 瀏覽:229
qq非主流圖片女生帶字 瀏覽:849
移動端js地圖 瀏覽:570
春雨大數據是什麼 瀏覽:47

友情鏈接