我在编写JApplet的页面的时候发现在web中的java框就那么大,我需要大点不知道怎么设置,请高手指点一下
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;public class BinarySearch extends JApplet implements ActionListener{
JLabel enterLabel,resultLabel;
JTextField enterField,resultField;
JTextArea output;
int array[];
String display="";
public void init()
{
Container container=getContentPane();
container.setLayout(new FlowLayout());
enterLabel=new JLabel("Enter integer search key");
container.add(enterLabel);
enterField=new JTextField(10);
container.add(enterField);
enterField.addActionListener(this);
resultLabel=new JLabel("Result");
container.add(resultLabel);
resultField=new JTextField(20);
resultField.setEditable(false);
container.add(resultField);
output=new JTextArea(6,60);
output.setFont(new Font("Monospaced",Font.PLAIN,12));
container.add(output);
array=new int[15];
for(int counter=0;counter<array.length;counter++)
array[counter]=2*counter;
}
public void actionPerformed(ActionEvent actionEvent)
{
String searchKey=actionEvent.getActionCommand();
display="Portions of array searched\n";
int element=binarySearch(array,Integer.parseInt(searchKey));
output.setText(display);
if(element!=-1) 
resultField.setText("Found value in element"+element);
else
resultField.setText("Value not found");
}

public int binarySearch(int array2[],int key)
{
int low=0;
int high=array2.length-1;
int middle;
while(low<=high){
middle=(low+high)/2;
buildOutput(array2,low,middle,high);
if(key==array[middle])
return middle;
else if (key<array[middle])
high=middle-1;
else 
low=middle+1;
}
return -1;
}
void buildOutput(int array3[],int low,int middle,int high)
{
DecimalFormat twoDigits=new DecimalFormat("00");
for(int counter=0;counter<array3.length;counter++){
if(counter<low||counter>high)
display+="   ";
else if(counter==middle)
display+=twoDigits.format(array3[counter])+"* ";
else
display+=twoDigits.format(array3[counter])+"  ";
}
display+="\n";
}
}

解决方案 »

  1.   

    applet有个方法好像是setSize(int,int)或reSize(int ,int),好久不写applet了,记不清了,你找找api文档就知道了。
      

  2.   

    是resize(int,int)和resize(Dimension d)两个方法,可以设定applet的宽高。
      

  3.   

    在html文件里面设置Width和Height不就行了吗?
      

  4.   

    在html文件里面设置Width和Height不就行了吗?
      

  5.   

    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import javax.swing.*;public class BinarySearch extends JApplet implements ActionListener{
    JLabel enterLabel,resultLabel;
    JTextField enterField,resultField;
    JTextArea output;
    int array[];
    String display="";
    public void init()
    {
    Container container=getContentPane();
    container.setLayout(new FlowLayout());
    enterLabel=new JLabel("Enter integer search key");
    container.add(enterLabel);
    enterField=new JTextField(10);
    container.add(enterField);
    enterField.addActionListener(this);
    resultLabel=new JLabel("Result");
    container.add(resultLabel);
    resultField=new JTextField(20);
    resultField.setEditable(false);
    container.add(resultField);
    output=new JTextArea(6,60);
    output.setFont(new Font("Monospaced",Font.PLAIN,12));
    container.add(output);
    array=new int[15];
    for(int counter=0;counter<array.length;counter++)
    array[counter]=2*counter;
    }
    public void actionPerformed(ActionEvent actionEvent)
    {
    String searchKey=actionEvent.getActionCommand();
    display="Portions of array searched\n";
    int element=binarySearch(array,Integer.parseInt(searchKey));
    output.setText(display);
    if(element!=-1) 
    resultField.setText("Found value in element"+element);
    else
    resultField.setText("Value not found");
    }public int binarySearch(int array2[],int key)
    {
    int low=0;
    int high=array2.length-1;
    int middle;
    while(low<=high){
    middle=(low+high)/2;
    buildOutput(array2,low,middle,high);
    if(key==array[middle])
    return middle;
    else if (key<array[middle])
    high=middle-1;
    else 
    low=middle+1;
    }
    return -1;
    }
    void buildOutput(int array3[],int low,int middle,int high)
    {
    DecimalFormat twoDigits=new DecimalFormat("00");
    for(int counter=0;counter<array3.length;counter++){
    if(counter<low||counter>high)
    display+="   ";
    else if(counter==middle)
    display+=twoDigits.format(array3[counter])+"* ";
    else
    display+=twoDigits.format(array3[counter])+"  ";
    }
    display+="\n";
    }
    }//width=200 height=300