为什么绘画不到第二个长方形?import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;
import java.applet.Applet;
import java.awt.Graphics;
public class sss3 extends Applet{

int number1;
int number2;
int number3;
int number4; int number5;
int number6;
int number7;
int number8;
public void init(){

String firstnumber;
String secondnumber;
String thirdnumber;
String forthnumber;



     firstnumber=JOptionPane.showInputDialog("input the first number:");
     secondnumber=JOptionPane.showInputDialog("input the second number:");
     thirdnumber=JOptionPane.showInputDialog("input the third number:");
     forthnumber=JOptionPane.showInputDialog("input the forth number:");
     
     
     number1=Integer.parseInt(firstnumber);
     number2=Integer.parseInt(secondnumber);
     number3=Integer.parseInt(thirdnumber);
     number4=Integer.parseInt(forthnumber);
       
}
public void init2(){ String firstnumber2;
String secondnumber2;
String thirdnumber2;
String forthnumber2;
  firstnumber2=JOptionPane.showInputDialog("input the first2 number:");
 secondnumber2=JOptionPane.showInputDialog("input the second2 number:");
 thirdnumber2=JOptionPane.showInputDialog("input the third2 number:");
 forthnumber2=JOptionPane.showInputDialog("input the forth2 number:");
     
               number5=Integer.parseInt(firstnumber2);
     number6=Integer.parseInt(secondnumber2);
     number7=Integer.parseInt(thirdnumber2);
     number8=Integer.parseInt(forthnumber2);
     

}     
           
 
  public void paint(Graphics g)
  {   
     g.drawRect(number1,number2, number3, number4);
  }
  
  
  public void paint2(Graphics h)
  {   
     h.drawRect(number5,number6, number7, number8);
  }
      
 
}  

解决方案 »

  1.   

    你是问init2和paint2为什么不执行?applet自己中只会运行init和paint的,不会运行init2和paint2的,你要运行的话必须自己调用
    import java.awt.Graphics;
    import javax.swing.JApplet;
    import javax.swing.JOptionPane;
    import java.applet.Applet;
    import java.awt.Graphics;public class sss3 extends Applet
    {
    int number1;
    int number2;
    int number3;
    int number4;
    int number5;
    int number6;
    int number7;
    int number8;

    public void init()
    {
    String firstnumber;
    String secondnumber;
    String thirdnumber;
    String forthnumber;

    firstnumber=JOptionPane.showInputDialog("input the first number:");
    secondnumber=JOptionPane.showInputDialog("input the second number:");
    thirdnumber=JOptionPane.showInputDialog("input the third number:");
    forthnumber=JOptionPane.showInputDialog("input the forth number:");

    number1=Integer.parseInt(firstnumber);
    number2=Integer.parseInt(secondnumber);
    number3=Integer.parseInt(thirdnumber);
    number4=Integer.parseInt(forthnumber);

    init2();
    }

    public void init2()
    {
    String firstnumber2;
    String secondnumber2;
    String thirdnumber2;
    String forthnumber2; firstnumber2=JOptionPane.showInputDialog("input the first2 number:");
    secondnumber2=JOptionPane.showInputDialog("input the second2 number:");
    thirdnumber2=JOptionPane.showInputDialog("input the third2 number:");
    forthnumber2=JOptionPane.showInputDialog("input the forth2 number:");

    number5=Integer.parseInt(firstnumber2);
    number6=Integer.parseInt(secondnumber2);
    number7=Integer.parseInt(thirdnumber2);
    number8=Integer.parseInt(forthnumber2);
    }   

    public void paint(Graphics g)
    {
    g.drawRect(number1,number2, number3, number4);

    paint2(g);
    }
      
    public void paint2(Graphics h)
    {   
    h.drawRect(number5,number6, number7, number8);
    }