import java.awt.Container;import javax.swing.*;public class MaximumTest extends JApplet {
public void init()
{
String s1 = JOptionPane.showInputDialog(
"Enter first floating-point value" );
String s2 = JOptionPane.showInputDialog(
"Enter second floating-point value" );
String s3 = JOptionPane.showInputDialog(
"Enter third floating-point value" );
double number1 = Double.parseDouble( s1 );
double number2 = Double.parseDouble( s2 );
double number3 = Double.parseDouble( s3 ); double max = maximum( number1, number2, number3 );
JTextArea outputArea = new JTextArea();
outputArea.setText( "number1: " + number1 + "\nnumber2: " +
number2 + "\nnumber3: " + number3 + "\nmaximum is: " + max );
Container container = new Container();//为什么不能改成这样呢?说下具体的原因细节!~ 嗷呜!
container.add( outputArea ); }
public double maximum( double x, double y, double z )
{
return Math.max( x, Math.max( y, z ) ); } }
public void init()
{
String s1 = JOptionPane.showInputDialog(
"Enter first floating-point value" );
String s2 = JOptionPane.showInputDialog(
"Enter second floating-point value" );
String s3 = JOptionPane.showInputDialog(
"Enter third floating-point value" );
double number1 = Double.parseDouble( s1 );
double number2 = Double.parseDouble( s2 );
double number3 = Double.parseDouble( s3 ); double max = maximum( number1, number2, number3 );
JTextArea outputArea = new JTextArea();
outputArea.setText( "number1: " + number1 + "\nnumber2: " +
number2 + "\nnumber3: " + number3 + "\nmaximum is: " + max );
Container container = new Container();//为什么不能改成这样呢?说下具体的原因细节!~ 嗷呜!
container.add( outputArea ); }
public double maximum( double x, double y, double z )
{
return Math.max( x, Math.max( y, z ) ); } }
public void init()
{
String s1 = JOptionPane.showInputDialog(
"Enter first floating-point value" );
String s2 = JOptionPane.showInputDialog(
"Enter second floating-point value" );
String s3 = JOptionPane.showInputDialog(
"Enter third floating-point value" );
double number1 = Double.parseDouble( s1 );
double number2 = Double.parseDouble( s2 );
double number3 = Double.parseDouble( s3 ); double max = maximum( number1, number2, number3 );
JTextArea outputArea = new JTextArea();
outputArea.setText( "number1: " + number1 + "\nnumber2: " +
number2 + "\nnumber3: " + number3 + "\nmaximum is: " + max );
//Container container = new Container();//JApplet当前默认有一个Container对象,你创建了一个新的对象,谁知道呢?
add( outputArea ); }
public double maximum( double x, double y, double z )
{
return Math.max( x, Math.max( y, z ) ); } }
你的container.add( outputArea );只是把outputArea 加上去了 但是 Container没有加上去
为什么不可以呀,
只要你有时间写把它的那些属性设置了就可以了呀
只是它是多数容器的基类,一般不那么用而以。
因为没有必要....
所以本身就是个Container了。
this.getContentPane().add(outputArea);
是不是就可以了,没有必要再创建一个Container