DragonPC_??? 兄:
我的代碼是這樣寫的怎一點反應都沒有
還有我把 timer = new Thread(this) ;
改成 timer = new Thread() ;
要不我編譯不能通過 能幫我看看嗎
謝謝
package myapplit;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.beans.*;
import com.borland.jbcl.layout.*;
import com.borland.dbswing.*;
import java.lang.Object.*;
import java.lang.Thread.*;
public class Applet1 extends JApplet {
boolean isStandalone = false;
public XYLayout xYLayout1;
public JPanel jPanel1;
public XYLayout xYLayout2;
public Button button1;
public MenuBar menuBar1;
JProgressBar JB = new JProgressBar();
JLabel jLabel2 = new JLabel();
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
/**Construct the applet*/
public Applet1() {
}
/**Initialize the applet*/
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
xYLayout1 = (XYLayout) Beans.instantiate(getClass().getClassLoader(), XYLayout.class.getName());
jPanel1 = (JPanel) Beans.instantiate(getClass().getClassLoader(), JPanel.class.getName());
xYLayout2 = (XYLayout) Beans.instantiate(getClass().getClassLoader(), XYLayout.class.getName());
button1 = (Button) Beans.instantiate(getClass().getClassLoader(), Button.class.getName());
menuBar1 = (MenuBar) Beans.instantiate(getClass().getClassLoader(), MenuBar.class.getName());
this.setForeground(Color.white);
this.getContentPane().setBackground(Color.lightGray);
this.setSize(new Dimension(400,300));
this.getContentPane().setLayout(xYLayout1);
jPanel1.setLayout(xYLayout2);
button1.setLabel("button1");
button1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
button1_actionPerformed(e);
}
});
jLabel2.setText("jLabel2");
this.getContentPane().add(jPanel1, new XYConstraints(0, 0, 383, 249));
jPanel1.add(JB, new XYConstraints(21, 97, 249, -1));
jPanel1.add(button1, new XYConstraints(174, 182, 76, 27));
jPanel1.add(jLabel2, new XYConstraints(34, 122, -1, -1));
}
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
}
/**Get parameter info*/
public String[][] getParameterInfo() {
return null;
}
/**Main method*/
public static void main(String[] args) {
Applet1 applet = new Applet1();
applet.isStandalone = true;
JFrame frame = new JFrame();
//EXIT_ON_CLOSE == 3
frame.setDefaultCloseOperation(3);
frame.setTitle("Applet Frame");
frame.getContentPane().add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(400,320);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
}
//static initializer for setting look &
feel
static {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e) {
}
}
void jComboBox1_itemStateChanged(ItemEvent e) {
}
void button1_actionPerformed(ActionEvent e) {
start() ;
for (int i=0;
i<100;
i++) {
try {
// Thread.sleep(50);
} catch (Exception ex) {}
setBarValue(i) ;
}
}
int nValue = 0 ;
synchronized void setBarValue(int nValue) {
this.nValue = nValue ;
}
synchronized int getBarValue() {
return nValue ;
}
Thread timer = null ;
public void start () {
if (timer == null) {
timer = new Thread() ;
timer.start() ;
}
}
public void stop() {
timer = null ;
}
public void run() {
while((timer != null) &&
(getBarValue() < 100)) {
try {
Thread.currentThread().sleep(10);
} catch (Exception ee) {}
JB.setValue(getBarValue());
jLabel2.setText(Integer.toString(getBarValue()));
jLabel2.paintImmediately(0,0,jLabel2.getWidth(), jLabel2.getHeight());
JB.paintImmediately(0,0,JB.getWidth(), JB.getHeight());
}
}
}