私はJavaの初心者で、最初のプロジェクトの二次方程式ソルバーを作成しました。Windows(私が開発したプラットフォーム)では正常に動作しますが、他のプラットフォームでも動作するはずです(そうではありませんか?)。さて、これはLinux(BackBox、PuppyLinux)では動作しません。試してみましたが、実行可能ファイルではないことがわかりました。この失敗の考えられる原因は何でしょうか?
PS私は本当に「クロスプラットフォーム」、特にJavaの初心者です。
コードは次のとおりです。
/*
* QuadraticEquations.java
*
* Created on Mar 17, 2012, 8:37:16 PM
*/
/**
*
* @author Afaan
*/
public class QuadraticEquations extends javax.swing.JFrame {
/** Creates new form QuadraticEquations */
public QuadraticEquations() {
initComponents();
}
/** 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">//GEN-BEGIN:initComponents
private void initComponents() {
MainPanel = new javax.swing.JPanel();
HeaderLabel = new javax.swing.JLabel();
AuthorLabel = new javax.swing.JLabel();
SubHeaderLabel = new javax.swing.JLabel();
a_Label = new javax.swing.JLabel();
b_Label = new javax.swing.JLabel();
c_Label = new javax.swing.JLabel();
a_Value = new javax.swing.JTextField();
b_Value = new javax.swing.JTextField();
c_Value = new javax.swing.JTextField();
calc_Button = new javax.swing.JButton();
ResultLabel = new javax.swing.JLabel();
Root1_Label = new javax.swing.JLabel();
Root2_Label = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Quadratic Equations Roots Calculator");
HeaderLabel.setFont(new java.awt.Font("Lucida Fax", 1, 18)); // NOI18N
HeaderLabel.setForeground(new java.awt.Color(0, 0, 255));
HeaderLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
HeaderLabel.setText("Quadratic Equations - Roots Calculator");
AuthorLabel.setFont(new java.awt.Font("Lucida Fax", 1, 14)); // NOI18N
AuthorLabel.setForeground(new java.awt.Color(0, 165, 0));
AuthorLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
AuthorLabel.setText("Afaan Bilal");
SubHeaderLabel.setFont(new java.awt.Font("Lucida Fax", 1, 12)); // NOI18N
SubHeaderLabel.setText("Enter the values of 'a', 'b', 'c' : ");
a_Label.setFont(new java.awt.Font("Lucida Fax", 1, 12)); // NOI18N
a_Label.setForeground(new java.awt.Color(25, 22, 200));
a_Label.setText("\" a \" :");
b_Label.setFont(new java.awt.Font("Lucida Fax", 1, 12)); // NOI18N
b_Label.setForeground(new java.awt.Color(25, 22, 200));
b_Label.setText("\" b \" :");
c_Label.setFont(new java.awt.Font("Lucida Fax", 1, 12)); // NOI18N
c_Label.setForeground(new java.awt.Color(25, 22, 200));
c_Label.setText("\" c \" :");
a_Value.setText("1");
b_Value.setText("2");
c_Value.setText("1");
calc_Button.setText("Calculate Roots!");
calc_Button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CalculateRoots(evt);
}
});
ResultLabel.setFont(new java.awt.Font("Lucida Fax", 1, 14)); // NOI18N
ResultLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
Root1_Label.setFont(new java.awt.Font("Lucida Fax", 1, 12)); // NOI18N
Root1_Label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
Root2_Label.setFont(new java.awt.Font("Lucida Fax", 1, 12)); // NOI18N
Root2_Label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
javax.swing.GroupLayout MainPanelLayout = new javax.swing.GroupLayout(MainPanel);
MainPanel.setLayout(MainPanelLayout);
MainPanelLayout.setHorizontalGroup(
MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, MainPanelLayout.createSequentialGroup()
.addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, MainPanelLayout.createSequentialGroup()
.addGap(149, 149, 149)
.addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(b_Label)
.addComponent(a_Label, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(c_Label))
.addGap(18, 18, 18)
.addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(c_Value)
.addComponent(b_Value)
.addComponent(a_Value, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))
.addGap(69, 69, 69))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, MainPanelLayout.createSequentialGroup()
.addGap(41, 41, 41)
.addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(ResultLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
.addComponent(SubHeaderLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Root2_Label, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
.addComponent(Root1_Label, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE))))
.addContainerGap())
.addGroup(MainPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(HeaderLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
.addGap(41, 41, 41))
.addGroup(MainPanelLayout.createSequentialGroup()
.addGap(167, 167, 167)
.addComponent(AuthorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(184, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, MainPanelLayout.createSequentialGroup()
.addContainerGap(176, Short.MAX_VALUE)
.addComponent(calc_Button, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(148, 148, 148))
);
MainPanelLayout.setVerticalGroup(
MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(MainPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(HeaderLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(AuthorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(SubHeaderLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(a_Value, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(a_Label))
.addGap(11, 11, 11)
.addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(b_Value, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(b_Label))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(c_Value, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(c_Label))
.addGap(18, 18, 18)
.addComponent(calc_Button)
.addGap(33, 33, 33)
.addComponent(ResultLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Root1_Label, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Root2_Label, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(MainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(MainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void CalculateRoots(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CalculateRoots
double a = (double)(Double.parseDouble(a_Value.getText()));
double b = (double)(Double.parseDouble(b_Value.getText()));
double c = (double)(Double.parseDouble(c_Value.getText()));
double D = 0.0;
double r1 = 0.0;
double r2 = 0.0;
if (a == 0)
{
ResultLabel.setText("Error: The value of \"a\" cannot be zero.");
Root1_Label.setText("");
Root2_Label.setText("");
}
else
{
D = (b * b) - 4 * a * c;
if (D < 0)
{
ResultLabel.setText("Error: The value of \"D\" is less than zero.");
Root1_Label.setText("Therefore, Real roots do not exist.");
Root2_Label.setText("");
}
else
{
r1 = ( - b + Math.sqrt(D) ) / 2 * a;
r2 = ( - b - Math.sqrt(D) ) / 2 * a;
ResultLabel.setText("The value of \"D\" is " + D + "");
Root1_Label.setText("The first root is " + r1 + "");
Root2_Label.setText("The second root is " + r2 + "");
}
}
}//GEN-LAST:event_CalculateRoots
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* 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(QuadraticEquations.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(QuadraticEquations.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(QuadraticEquations.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(QuadraticEquations.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new QuadraticEquations().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel AuthorLabel;
private javax.swing.JLabel HeaderLabel;
private javax.swing.JPanel MainPanel;
private javax.swing.JLabel ResultLabel;
private javax.swing.JLabel Root1_Label;
private javax.swing.JLabel Root2_Label;
private javax.swing.JLabel SubHeaderLabel;
private javax.swing.JLabel a_Label;
private javax.swing.JTextField a_Value;
private javax.swing.JLabel b_Label;
private javax.swing.JTextField b_Value;
private javax.swing.JLabel c_Label;
private javax.swing.JTextField c_Value;
private javax.swing.JButton calc_Button;
// End of variables declaration//GEN-END:variables
}
JVMをインストールし、それを単純なJAR実行可能ファイルにコンパイルします。指定された主なクラスはですQuadraticEquations
。Windowsでは正常に実行および動作しますが、Linuxでは正常に動作しません。