can anyone tell me why this project(attached) is slow in execution!!!!
is there any remedy for this problem......
please anyone tell some tip to make this project to run faster..........
can anyone tell me why this project(attached) is slow in execution!!!!
is there any remedy for this problem......
please anyone tell some tip to make this project to run faster..........
i have now modified the above attached code somehow...........reduced the code to about 323 from 1000......
but still the code is running slowly...........according to me i think the problem is with the choice item allocation...........can anyone tell me how to solve this problem and make this code to run more faster than before...............
Please post the code on the forum.
pretty sure packing it in a jar file would increase running speed :)
all fun aside, as NormR1 mentioned, show your code.
we can't just go around and unzip-install-compile and run the entire project for everyone who posts a question about their code.
their are several reasons why your code might be slow: a thread temporarily blocking the execution of your program, or, an input file with a few thousand lines to process, or just one with ten to process ... there's a lot of possibilities out there.
Here is the code
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package project2;
/**
*
* @author nidhish
*/
public class Project2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* strength.java
*
* Created on Jul 3, 2011, 10:11:41 PM
*/
package project2;
import java.awt.Choice;
import javax.swing.*;
/**
*
* @author nidhish
*/
public class page1 extends javax.swing.JFrame {
public int val;
int i2=21;
public JLabel[] lb=new JLabel[25];
public JLabel[] lba=new JLabel[25];
public JLabel[] lbae=new JLabel[25];
public JLabel[] lbael=new JLabel[25];
public JLabel[] lbaels=new JLabel[25];
public JLabel[] lbaelss=new JLabel[25];
public Choice[] ch=new Choice[25];
public Choice[] cho=new Choice[25];
public Choice[] choi=new Choice[25];
public Choice[] choic=new Choice[25];
public Choice[] choice=new Choice[25];
public Choice[] choices=new Choice[25];
public page1() {
initComponents();
for(int f=1,j=90;f<=21;f++,j+=20)
{
ch[f] = new java.awt.Choice();
ch[f].setBounds(60, j, 55, 20);
jDesktopPane1.add(ch[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
cho[f] = new java.awt.Choice();
cho[f].setBounds(230, j, 55, 20);
jDesktopPane1.add(cho[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
choi[f] = new java.awt.Choice();
choi[f].setBounds(400, j, 55, 20);
jDesktopPane1.add(choi[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
choic[f] = new java.awt.Choice();
choic[f].setBounds(560, j, 55, 20);
jDesktopPane1.add(choic[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
choice[f] = new java.awt.Choice();
choice[f].setBounds(720, j, 55, 20);
jDesktopPane1.add(choice[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
choices[f] = new java.awt.Choice();
choices[f].setBounds(880, j, 55, 20);
jDesktopPane1.add(choices[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
lb[f] = new javax.swing.JLabel();
lb[f].setFont(new java.awt.Font("Tahoma", 1, 12));
lb[f].setText("S1 S2");
lb[f].setBounds(20, j, 36, 20);
jDesktopPane1.add(lb[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
lba[f] = new javax.swing.JLabel();
lba[f].setFont(new java.awt.Font("Tahoma", 1, 12));
lba[f].setText("S1 S2");
lba[f].setBounds(180, j, 36, 20);
jDesktopPane1.add(lba[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
lbae[f] = new javax.swing.JLabel();
lbae[f].setFont(new java.awt.Font("Tahoma", 1, 12));
lbae[f].setText("S1 S2");
lbae[f].setBounds(350, j, 36, 20);
jDesktopPane1.add(lbae[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
lbael[f] = new javax.swing.JLabel();
lbael[f].setFont(new java.awt.Font("Tahoma", 1, 12));
lbael[f].setText("S1 S2");
lbael[f].setBounds(510, j, 36, 20);
jDesktopPane1.add(lbael[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
lbaels[f] = new javax.swing.JLabel();
lbaels[f].setFont(new java.awt.Font("Tahoma", 1, 12));
lbaels[f].setText("S1 S2");
lbaels[f].setBounds(670, j, 36, 20);
jDesktopPane1.add(lbaels[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
lbaelss[f] = new javax.swing.JLabel();
lbaelss[f].setFont(new java.awt.Font("Tahoma", 1, 12));
lbaelss[f].setText("S1 S2");
lbaelss[f].setBounds(830, j, 36, 20);
jDesktopPane1.add(lbaelss[f], javax.swing.JLayeredPane.DEFAULT_LAYER);
}
for(int i=1;i<=21;i++)
{
for(int j=0;j<=100;j++)
{
if(j==0)
{
ch[i].addItem("");
cho[i].addItem("");
choi[i].addItem("");
choic[i].addItem("");
choice[i].addItem("");
choices[i].addItem("");
}
else
{
ch[i].addItem(""+j);
cho[i].addItem(""+j);
choi[i].addItem(""+j);
choic[i].addItem(""+j);
choice[i].addItem(""+j);
choices[i].addItem(""+j);
}
}
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jDesktopPane1 = new javax.swing.JDesktopPane();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel16 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jLabel17 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel19 = new javax.swing.JLabel();
jLabel20 = new javax.swing.JLabel();
jLabel21 = new javax.swing.JLabel();
jLabel22 = new javax.swing.JLabel();
jLabel23 = new javax.swing.JLabel();
jLabel18 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jDesktopPane1.setBackground(new java.awt.Color(204, 204, 204));
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel8.setText("MECHANICAL");
jLabel8.setPreferredSize(new java.awt.Dimension(88, 15));
jLabel8.setBounds(520, 10, 88, 15);
jDesktopPane1.add(jLabel8, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel9.setText("ENGINEERING");
jLabel9.setBounds(520, 30, 88, 15);
jDesktopPane1.add(jLabel9, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel11.setText("ELECTRONICS");
jLabel11.setPreferredSize(new java.awt.Dimension(88, 15));
jLabel11.setBounds(370, 25, 104, 15);
jDesktopPane1.add(jLabel11, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel10.setText("ELECTRICAL & ");
jLabel10.setPreferredSize(new java.awt.Dimension(88, 15));
jLabel10.setBounds(370, 10, 104, 15);
jDesktopPane1.add(jLabel10, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel7.setText(" COMPUTER");
jLabel7.setPreferredSize(new java.awt.Dimension(88, 15));
jLabel7.setBounds(190, 10, 88, 15);
jDesktopPane1.add(jLabel7, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel16.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel16.setText("ENGINEERING");
jLabel16.setPreferredSize(new java.awt.Dimension(88, 15));
jLabel16.setBounds(370, 40, 104, 20);
jDesktopPane1.add(jLabel16, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel2.setText(" INFORMATION");
jLabel2.setPreferredSize(new java.awt.Dimension(88, 15));
jLabel2.setBounds(30, 10, 101, 15);
jDesktopPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel6.setText(" SCIENCE");
jLabel6.setBounds(190, 30, 88, 15);
jDesktopPane1.add(jLabel6, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel15.setText("ENGINEERING");
jLabel15.setBounds(840, 30, 80, 15);
jDesktopPane1.add(jLabel15, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel17.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel17.setText(" CIVIL");
jLabel17.setPreferredSize(new java.awt.Dimension(88, 15));
jLabel17.setBounds(840, 10, 88, 10);
jDesktopPane1.add(jLabel17, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel13.setText("COMMUNICATION");
jLabel13.setPreferredSize(new java.awt.Dimension(88, 15));
jLabel13.setBounds(680, 20, 115, 20);
jDesktopPane1.add(jLabel13, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel14.setText("ENGINEERING");
jLabel14.setPreferredSize(new java.awt.Dimension(88, 15));
jLabel14.setBounds(680, 30, 104, 30);
jDesktopPane1.add(jLabel14, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel12.setText("ELECTRONICS & ");
jLabel12.setPreferredSize(new java.awt.Dimension(88, 15));
jLabel12.setBounds(680, 10, 104, 10);
jDesktopPane1.add(jLabel12, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel3.setText(" TECHNOLOGY");
jLabel3.setBounds(30, 30, 87, 15);
jDesktopPane1.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel19.setText(" STRENGTH");
jLabel19.setBounds(50, 70, 80, 14);
jDesktopPane1.add(jLabel19, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel20.setText(" STRENGTH");
jLabel20.setBounds(220, 70, 80, 14);
jDesktopPane1.add(jLabel20, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel21.setText(" STRENGTH");
jLabel21.setBounds(390, 70, 80, 14);
jDesktopPane1.add(jLabel21, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel22.setText(" STRENGTH");
jLabel22.setBounds(550, 70, 80, 14);
jDesktopPane1.add(jLabel22, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel23.setText(" STRENGTH");
jLabel23.setBounds(710, 70, 80, 14);
jDesktopPane1.add(jLabel23, javax.swing.JLayeredPane.DEFAULT_LAYER);
jLabel18.setText(" STRENGTH");
jLabel18.setBounds(870, 70, 80, 14);
jDesktopPane1.add(jLabel18, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(29, 29, 29)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 960, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(37, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 551, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(283, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new page1().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel17;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel19;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel20;
private javax.swing.JLabel jLabel21;
private javax.swing.JLabel jLabel22;
private javax.swing.JLabel jLabel23;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
// End of variables declaration
}
I rather would not comment on it or I wouldn't know where to stop
Changing from Choice (AWT component) to JComboBox (Swing component) cuts the time in half roughly.
Using JTextfield makes it nearly instant and I can't see any benefit at all to using the combo boxes to choose a number 1-100.
Seems like a JTable would be a preferable UI choice.
If you're curious where the time is spent, add some printlns to show the current time at different points in the code.
System.out.println("end loop1 " + System.currentTimeMillis());
Also try using the -Xprof option to print out profiling stats.
I run the program in netbeans and it run fast because it does nothing. Maybe something is wrong with your computer or you're using netbeans in a wrong way.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.