运行应用程序时框架出现空白(JAVA)

发布于 2024-10-31 15:45:15 字数 2810 浏览 0 评论 0原文

因此,在一些人的帮助下,我能够编译并运行这段代码。但现在,另一个问题又出现了。运行应用程序时,面板为空白。我是个新手,我知道我在做一些愚蠢的事情。我整晚都坐在这里,试图让它充分发挥作用,但不知道我还需要做什么才能让它发挥作用。

 import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Graphics;
import javax.swing.JOptionPane;
import javax.swing.JApplet;
import java.awt.event.*;

public class telephoneKeypad extends javax.swing.JFrame
{


    public void telephoneKeypad()
    {
        Panel pnlKeyPad = new Panel();
          GridLayout gridLayout1 = new GridLayout();
          Button btnZero = new Button();
          Button btnOne = new Button();
          Button btnTwo = new Button();
          Button btnThree = new Button();
        Button btnFour = new Button();
          Button btnFive = new Button();
          Button btnSix = new Button();
          Button btnSeven = new Button();
          Button btnEight = new Button();
          Button btnNine = new Button();
          Button btnStar = new Button();
          Button btnHash = new Button();

        TextField tfNumber = new TextField();
          Button btnDial = new Button();
          BorderLayout borderLayout1 = new BorderLayout();
          Panel pnlNumberEntry = new Panel();
          FlowLayout flowLayout1 = new FlowLayout();





            btnOne.setLabel("1");
            btnTwo.setLabel("2");
            btnThree.setLabel("3");
            btnFour.setLabel("4");
            btnFive.setLabel("5");
            btnSix.setLabel("6");
            btnSeven.setLabel("7");
            btnEight.setLabel("8");
            btnNine.setLabel("9");
            btnStar.setLabel("*");
            btnZero.setLabel("0");
            btnHash.setLabel("#");
            btnDial.setLabel("Dial");

            pnlNumberEntry.setLayout(flowLayout1);
            pnlKeyPad.setLayout(gridLayout1);
            this.setLayout(borderLayout1);
            this.add(pnlNumberEntry, BorderLayout.NORTH);
            pnlNumberEntry.add(tfNumber, null);
            pnlNumberEntry.add(btnDial, null);
            this.add(pnlKeyPad, BorderLayout.CENTER);
            pnlKeyPad.add(btnOne, null);
            pnlKeyPad.add(btnTwo, null);
            pnlKeyPad.add(btnThree, null);
            pnlKeyPad.add(btnFour, null);
            pnlKeyPad.add(btnFive, null);
            pnlKeyPad.add(btnSix, null);
            pnlKeyPad.add(btnSeven, null);
            pnlKeyPad.add(btnEight, null);
            pnlKeyPad.add(btnNine, null);
            pnlKeyPad.add(btnStar, null);
            pnlKeyPad.add(btnZero, null);
            pnlKeyPad.add(btnHash, null);
        }

            public static void main(String args[])
                {
                telephoneKeypad kpad = new telephoneKeypad();
                kpad.setBounds(500, 500, 500, 500);
                kpad.setVisible(true);
    }
 }

So, with the help of some guys here, I was able to get this code to compile and run. But now, another problem has presented itself. When running the application, the panel is blank. I'm a newb, and i know i'm doing something stupid. I've been sitting here all night trying to get this to fully work, but can't figure out what else I need to do to get it to work.

 import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Graphics;
import javax.swing.JOptionPane;
import javax.swing.JApplet;
import java.awt.event.*;

public class telephoneKeypad extends javax.swing.JFrame
{


    public void telephoneKeypad()
    {
        Panel pnlKeyPad = new Panel();
          GridLayout gridLayout1 = new GridLayout();
          Button btnZero = new Button();
          Button btnOne = new Button();
          Button btnTwo = new Button();
          Button btnThree = new Button();
        Button btnFour = new Button();
          Button btnFive = new Button();
          Button btnSix = new Button();
          Button btnSeven = new Button();
          Button btnEight = new Button();
          Button btnNine = new Button();
          Button btnStar = new Button();
          Button btnHash = new Button();

        TextField tfNumber = new TextField();
          Button btnDial = new Button();
          BorderLayout borderLayout1 = new BorderLayout();
          Panel pnlNumberEntry = new Panel();
          FlowLayout flowLayout1 = new FlowLayout();





            btnOne.setLabel("1");
            btnTwo.setLabel("2");
            btnThree.setLabel("3");
            btnFour.setLabel("4");
            btnFive.setLabel("5");
            btnSix.setLabel("6");
            btnSeven.setLabel("7");
            btnEight.setLabel("8");
            btnNine.setLabel("9");
            btnStar.setLabel("*");
            btnZero.setLabel("0");
            btnHash.setLabel("#");
            btnDial.setLabel("Dial");

            pnlNumberEntry.setLayout(flowLayout1);
            pnlKeyPad.setLayout(gridLayout1);
            this.setLayout(borderLayout1);
            this.add(pnlNumberEntry, BorderLayout.NORTH);
            pnlNumberEntry.add(tfNumber, null);
            pnlNumberEntry.add(btnDial, null);
            this.add(pnlKeyPad, BorderLayout.CENTER);
            pnlKeyPad.add(btnOne, null);
            pnlKeyPad.add(btnTwo, null);
            pnlKeyPad.add(btnThree, null);
            pnlKeyPad.add(btnFour, null);
            pnlKeyPad.add(btnFive, null);
            pnlKeyPad.add(btnSix, null);
            pnlKeyPad.add(btnSeven, null);
            pnlKeyPad.add(btnEight, null);
            pnlKeyPad.add(btnNine, null);
            pnlKeyPad.add(btnStar, null);
            pnlKeyPad.add(btnZero, null);
            pnlKeyPad.add(btnHash, null);
        }

            public static void main(String args[])
                {
                telephoneKeypad kpad = new telephoneKeypad();
                kpad.setBounds(500, 500, 500, 500);
                kpad.setVisible(true);
    }
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后来的我们 2024-11-07 15:45:15

您声明了错误的构造函数 - public void TelephoneKeypad() 而不是 public TelephoneKeypad()

您仍然需要在面板上工作,但这实际上会运行您的构造函数,而不是默认构造函数。

另外,通常类名以大写字母开头。

You declared the constructor wrong - public void telephoneKeypad() instead of public telephoneKeypad()

You would still have to work on the panels, but this will actually run your constructor and not the default constructor.

Also, usually class name start with Uppercase letter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文