Is there a way to repaint this AWT applet of mine little bit faster? If I have 10 columns and 20 rows of textFields, when I repaint the applet, I can literally "see" the repainting being done, like an unseen hand sweeping clean the fields and then another hand putting the new fields in places. I will need to do better.
Does anyone have an advice? Thank you. import java.applet.Applet; import java.awt.*; import java.awt.event.*;
public class Test1112 extends Applet { int no_of_rec = 0; int index = 0;
String[] data; Panel p1; GridBagConstraints c1; Panel pMain; Color pnlBgColor = new Color(144, 196, 222);
Panel cPanel;
public void init(){
data = getData(index); no_of_rec = data.length;
//main Panel pMain = new Panel(); pMain.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); pMain.setBackground(pnlBgColor);
//p0 Panel p0 = new Panel(); p0.setLayout(new GridBagLayout()); GridBagConstraints c0 = new GridBagConstraints(); c0.fill = GridBagConstraints.HORIZONTAL; p0.setBackground(pnlBgColor);
//p1 p1 = new Panel(); p1.setLayout(new GridBagLayout()); c1 = new GridBagConstraints();
//call a method to add data row(s) addDataPanel(p1, c1);
//add p0 and p1 to pMain; c.gridx = 0; c.gridy = 0; pMain.add(p0, c);
c.gridx = 0; c.gridy = 1; pMain.add(p1, c);
//p2 Panel p2 = new Panel(); p2.setLayout(new GridBagLayout()); GridBagConstraints c2 = new GridBagConstraints(); c2.fill = GridBagConstraints.HORIZONTAL; p2.setBackground(pnlBgColor);
c.gridx = 0; c.gridy = 2; pMain.add(p2, c);
display(data);
add(pMain);
this.setBackground(pnlBgColor);
}//init
private String[] getData(int i){
int n = 0; if((i%2) == 0) n= 20; else n= 18; String[] data = new String[n]; for(int j=0; j < data.length; j++){ data[j] = "000000" + String.valueOf(j); } return data; }
private void addDataPanel(Panel p1, GridBagConstraints c1){ txtDataRowDisplay1 = new TextField[no_of_rec]; txtDataRowDisplay2 = new TextField[no_of_rec]; txtDataRowDisplay3 = new TextField[no_of_rec]; txtDataRowDisplay4 = new TextField[no_of_rec]; txtDataRowDisplay5 = new TextField[no_of_rec]; txtDataRowDisplay6 = new TextField[no_of_rec]; txtDataRowDisplay7 = new TextField[no_of_rec]; txtDataRowDisplay8 = new TextField[no_of_rec]; txtDataRowDisplay9 = new TextField[no_of_rec]; txtDataRowDisplay10 = new TextField[no_of_rec];
//initialize fields for(int i = 0; i < no_of_rec; i++){ txtDataRowDisplay1[i] = new TextField(5); txtDataRowDisplay2[i] = new TextField(5); txtDataRowDisplay3[i] = new TextField(5); txtDataRowDisplay4[i] = new TextField(5); txtDataRowDisplay5[i] = new TextField(5); txtDataRowDisplay6[i] = new TextField(5); txtDataRowDisplay7[i] = new TextField(5); txtDataRowDisplay8[i] = new TextField(5); txtDataRowDisplay9[i] = new TextField(5); txtDataRowDisplay10[i] = new TextField(5);
}
int cnt = 0; for(int m = 0; m < txtDataRowDisplay1.length; m++ ){