Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将类调用到网格中_Java_Class_Applet_Awt_Layout Manager - Fatal编程技术网

Java 将类调用到网格中

Java 将类调用到网格中,java,class,applet,awt,layout-manager,Java,Class,Applet,Awt,Layout Manager,我正在尝试为学校制作一个天气小程序,但是我在将一个班级调用到一个主班级时遇到了问题。最后,我将要3个永久组件的位置,温度,降水,然后在图像框中,我想做一个if语句,从组件中的数据pics适当的图像 布局理念 主类代码 密码 该GUI似乎非常适合包含在一个应用程序中 位置gui将置于BorderLayout.PAGE\u开始位置 图像将放在BorderLayout.CENTER中 温度将放在BorderLayout.LINE\u结束 拼写为precip的percip将放在BorderLayout.

我正在尝试为学校制作一个天气小程序,但是我在将一个班级调用到一个主班级时遇到了问题。最后,我将要3个永久组件的位置,温度,降水,然后在图像框中,我想做一个if语句,从组件中的数据pics适当的图像

布局理念 主类代码 密码
该GUI似乎非常适合包含在一个应用程序中

位置gui将置于BorderLayout.PAGE\u开始位置 图像将放在BorderLayout.CENTER中 温度将放在BorderLayout.LINE\u结束 拼写为precip的percip将放在BorderLayout.PAGE_END的位置 注意,沉淀条应该是另一个小程序!它应该只是一个组件

为了在BorderLayout中分配空间,自定义绘制的构件需要返回合理的首选尺寸

最好使用标签来显示文本,而不是自定义绘制这些内容。这样,我们就不需要重写paint方法或getPreferredSize。GUI将根据标签的自然大小进行提示。

为学校1制作一个天气小程序。请向老师咨询。2 AWT与Swing的相同交易。关于放弃使用AWT组件的许多好理由,请参见我的答案。JLabel可以轻松显示图像,而基于AWT的标签只支持文本。
// The "Weather" class.
import java.applet.*;
import javax.swing.*;
import java.awt.*;

public class Weather extends Applet
{
//TempBar Intergers
    //int x= 
    //int y=
    //int H=    //H = Heat

    //PercipBar Intergers
    //int x2=
    //int y2=
    //int P =   //P = pericipitation

    public void init ()
    {
       GridLayout umm = new GridLayout(0,2);
       PercipBar percip = new PercipBar();
       getContentPane.addItem (percip());
    } 

    public void paint (Graphics g)
    {
    } 
} 
import java.awt.*;
import java.applet.*;

public class PercipBar extends Applet 
{
     int x2 =2;
     int y2 =2;

     int P =80;//P = percipitation will be declared in main file

    public void paint (Graphics g)
    {
        g.setColor (Color.black);
        g.drawRect (x2, y2, 100, 20);//outline of bar
        g.setColor (Color.blue);
        g.fillRect (x2+1, y2+4, P, 14 ); //indicator bar (+4 puts space beetween outline bar)
    }
}