簡體   English   中英

不顯示對話框

[英]Doesn't show dialog

import    java.awt.*;
import    java.awt.event.*;
import    java.lang.*;

public  class Party {
    public static void main(String[] args){
        System.out.printf("Start\n");
        Frame  f = new Frame();
        Label  l = new Label("Party over here!");
        Button b = new Button("You bet") ;
        Button C = new Button("Shoot me");
        Panel  p = new Panel();
        p.add(l);
        System.out.printf("End\n");
    }  
}

為什么我沒有得到對話框? 示例中缺少什么?

public static void main(String[] args){
    System.out.printf("Start\n");
    Frame  f = new Frame();
    Label  l = new Label("Party over here!");
    Button b = new Button("You bet") ;
    Button C = new Button("Shoot me");
    Panel  p = new Panel();
    p.add(l);
    f.add(p);
    f.add(b);
    f.add(c);
    f.setVisible(true);//<-- make it visible...
    System.out.println("End");
}  

我想你需要閱讀一些關於java GUI的基礎知識,祝你好運。

在該示例中,該書在new Panel()行之后發表評論:

//more code here...

這意味着代碼不一定是功能性的。

通過添加一行f.setVisible(true); 你應該看到它。

添加到您的代碼:

f.setVisible(true);

好吧,你似乎已經制作了一個框架,一個標簽和一個按鈕,並在面板上放了一些東西。 但你有沒有展示框架?

使用f.setVisible(true);

如果你想使用一個框架,我建議你使用JFrame。

但是您指定了要顯示的對話框,這就是您執行此操作的方式:

JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.");

在這里查看有關對話框的更多信息:

http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#overview

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM