我在netbeans中以applet的形式制作了一个燃料成本计算器。当我在Netbeans中测试它时,一切正常,但我需要它在TextPad中为我的课程运行。当我运行程序时,我得到了这个错误的不同变体:包org.netbeans.lib.awextra不存在。这是我的代码:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Riley
*/
public class TGCApplet extends javax.swing.JApplet {
/**
* Initializes the applet TGCApplet
*/
@Override
public void init() {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TGCApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TGCApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TGCApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TGCApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the applet */
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* This method is called from within the init() method 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">//GEN-BEGIN:initComponents
private void initComponents() {
StartingPoint = new javax.swing.JComboBox<>();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
EndPoint = new javax.swing.JComboBox<>();
jLabel3 = new javax.swing.JLabel();
Size = new javax.swing.JComboBox<>();
jLabel4 = new javax.swing.JLabel();
GasType = new javax.swing.JComboBox<>();
jLabel5 = new javax.swing.JLabel();
CostPerGallon = new javax.swing.JTextField();
Miles = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
Submit = new javax.swing.JButton();
Clear = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
t1 = new javax.swing.JTextField();
t2 = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
t3 = new javax.swing.JTextField();
jLabel11 = new javax.swing.JLabel();
t5 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel12 = new javax.swing.JLabel();
t4 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
StartingPoint.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Minneapolis", "Madison", "Des Moines", "Bismarck", "Pierre", "Omaha" }));
StartingPoint.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
StartingPointActionPerformed(evt);
}
});
getContentPane().add(StartingPoint, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 110, -1));
jLabel1.setText("Beginning Locations");
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 20, -1, -1));
jLabel2.setText("Destination Location");
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 20, -1, -1));
EndPoint.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Minneapolis", "Madison", "Des Moines", "Bismarck", "Pierre", "Omaha" }));
EndPoint.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
EndPointActionPerformed(evt);
}
});
getContentPane().add(EndPoint, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 40, 100, -1));
jLabel3.setText("Vehicle Size");
getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 110, -1, -1));
Size.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Compact", "Mid Size", "Luxury", "SUV" }));
Size.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SizeActionPerformed(evt);
}
});
getContentPane().add(Size, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 130, 110, -1));
jLabel4.setText("Gas Type");
getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 110, -1, -1));
GasType.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Leaded", "Unleaded", "Super Unleaded", "Diesel" }));
getContentPane().add(GasType, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 130, 100, -1));
jLabel5.setText("Cost Per Gallon");
getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 110, -1, -1));
getContentPane().add(CostPerGallon, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 130, 90, -1));
Miles.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
MilesActionPerformed(evt);
}
});
getContentPane().add(Miles, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 40, 80, -1));
jLabel6.setText("Miles");
getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 20, -1, -1));
Submit.setText("Submit");
Submit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SubmitActionPerformed(evt);
}
});
getContentPane().add(Submit, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 200, -1, -1));
Clear.setText("Clear");
Clear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ClearActionPerformed(evt);
}
});
getContentPane().add(Clear, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 200, -1, -1));
jLabel7.setText("Custom Calculation");
getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 230, -1, -1));
jLabel8.setText("Miles traveling.");
getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 250, 90, -1));
getContentPane().add(t1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 270, 70, -1));
t2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
t2ActionPerformed(evt);
}
});
getContentPane().add(t2, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 270, 80, -1));
jLabel9.setText("Cost per gallon");
getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 250, 80, -1));
jLabel10.setText("Oil change cost (if any).");
getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 250, -1, -1));
t3.setText("0.00");
getContentPane().add(t3, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 270, 60, -1));
jLabel11.setText("Total");
getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 300, -1, -1));
t5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
t5ActionPerformed(evt);
}
});
getContentPane().add(t5, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 320, 90, -1));
jButton1.setText("Calculate");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 320, -1, -1));
jLabel12.setText("Enter fuel tank capacity.");
getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 250, -1, -1));
t4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
t4ActionPerformed(evt);
}
});
getContentPane().add(t4, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 270, 80, -1));
jButton2.setText("Clear");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 320, -1, -1));
}// </editor-fold>//GEN-END:initComponents
private void SubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SubmitActionPerformed
if(StartingPoint == EndPoint){
Miles.setText("0");
}
}//GEN-LAST:event_SubmitActionPerformed
private void StartingPointActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StartingPointActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_StartingPointActionPerformed
private void ClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_ClearActionPerformed
private void MilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MilesActionPerformed
}//GEN-LAST:event_MilesActionPerformed
private void EndPointActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EndPointActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_EndPointActionPerformed
private void SizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SizeActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_SizeActionPerformed
private void t2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_t2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
double a,b,c,d,e;
a = Double.parseDouble(t1.getText());
b = Double.parseDouble(t2.getText());
c = Double.parseDouble(t3.getText());
d = Double.parseDouble(t4.getText());
e = ((a*b)/d)+c;
t5.setText("$"+d);
}//GEN-LAST:event_jButton1ActionPerformed
private void t5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t5ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_t5ActionPerformed
private void t4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t4ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_t4ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
}//GEN-LAST:event_jButton2ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton Clear;
private javax.swing.JTextField CostPerGallon;
private javax.swing.JComboBox<String> EndPoint;
private javax.swing.JComboBox<String> GasType;
private javax.swing.JTextField Miles;
private javax.swing.JComboBox<String> Size;
private javax.swing.JComboBox<String> StartingPoint;
private javax.swing.JButton Submit;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JTextField t1;
private javax.swing.JTextField t2;
private javax.swing.JTextField t3;
private javax.swing.JTextField t4;
private javax.swing.JTextField t5;
// End of variables declaration//GEN-END:variables
}
答案 0 :(得分:0)
将netbeans安装中的文件java/modules/ext/AbsoluteLayout.jar
添加到类路径中。我不确定TextPad如何处理类路径,但是从命令行来看它会是这样的:
java -cp java/modules/ext/AbsoluteLayout.jar -jar yourjar.jar