0
ユニットコンバータを作成しています。変換を実行し、ラベルを貼り、いくつかのエラーをキャッチします。 lengthConversionメソッドとtimeConversionメソッドを呼び出すと、最初のエラーチェックが間違って表示され、答えが表示されません。私はそれが私がそれらを使用して動作するかどうかの文を知っている パッケージV4Converter;コンボボックスから呼び出しているメソッドは、すべてのコードを実行しません。そのコードの一部だけを実行します。
import java.awt.Toolkit;
import java.awt.event.ItemListener;
import java.text.DecimalFormat;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
public class v4Converter extends javax.swing.JFrame {
static final double[] TO_CENTM = {1,30.48,2.54,100000,160935,0.1,100,91.44};
static final double[] TO_FEET = {0.032808399,1,0.083333333334,3280.839895,5280.019685,0.0032808399,3.280839895,3};
static final double[] TO_INCHE ={0.3937007874,12,1,39370.07874,63360.23622, 0.0393700787,39.37007874,36} ;
static final double[] TO_KILOM = {0.00001,0.0003048,0.0000254,1,1.60935,0.000001,0.001,0.0009144 } ;
static final double[] TO_MILE = {0.0000062137,0.0001893932,0.0000157828,0.6213688756,1,6.213688756E-7,0.0006213689,0.0005681797};
static final double[] TO_MILIM = {10,304.8,25.4,1000000,1609350,1,1000,914.4};
static final double[] TO_METER = {0.01,0.3048,0.0254,0.001,1609.35,0.001,1,0.9144};
static final double[] TO_YARD = {0.010936133,0.3333333333,0.0277777778,1093.6132983,1760.0065617,1760.0065617,1};
static final double[] TO_DAY = {1,0.0416666667,1.157407407E-8, 0.0006944444,30.4375,0.0000115741,7,365.25};
static final double[] TO_HOUR = {24,1,2.777777777E-7,0.0166666667,730.5,0.0002777778,168,8766};
static final long[] TO_MILLIS = {86400000L,3600000L,1,60000L,2629800000L,1000L,604800000L,31557600000L};
static final double[] TO_MINUTE = {1440,60,0.0000166667,1,43830,0.0166666667,10080,525960};
static final double[] TO_MONTH = {0.0328542094,0.0013689254,3.802570537E-10,0.0000228154,1,0.2299794661,12};
static final double[] TO_SECONDS = {86400,3600,0.001,60,2629800,1,604800,31557600};
static final double[] TO_WEEK = {0.1428571429,0.005952381,1.653439153E-9,0.0000992063,4.3482142857, 0.0000016534,1,52.178571429};
static final double[] TO_YEAR = {0.0027378508,0.0001140771,3.168808781E-11,0.0000019013,0.0833333333,3.168808781E-8,0.0191649555,1};
static final String[] LENGTH_UNIT = {"Centimeters", "Feet", "Inches", "Kilometers", "Miles", "Millimeters", "Meters", "Yards"};
static final String[] TIME_UNIT = {"Days", "Hours", "Milliseconds", "Minutes", "Month", "Seconds", "Week", "Year"};
public static final DecimalFormat df1 = new DecimalFormat("#.##");
public static final DecimalFormat df2 = new DecimalFormat("#.0000000");
public v4Converter() {
initComponents();
setIcon();
setSize(350,250);
setLocationRelativeTo(null);
comboBoxFrom.setSelectedIndex(0);
comboBoxTo.setSelectedIndex(0);
}
@SuppressWarnings("unchecked")
private void initComponents() {
pnlAnswer = new javax.swing.JPanel();
lblAnswer = new javax.swing.JLabel();
btnConvert = new javax.swing.JButton();
comboBoxFrom = new javax.swing.JComboBox<>();
comboBoxTo = new javax.swing.JComboBox<>();
txtField1 = new javax.swing.JTextField();
btnReset = new javax.swing.JButton();
btnExit = new javax.swing.JButton();
lblConvertTo = new javax.swing.JLabel();
lblConvertFrom = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
pnlAnswer.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
lblAnswer.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
lblAnswer.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
javax.swing.GroupLayout pnlAnswerLayout = new javax.swing.GroupLayout(pnlAnswer);
pnlAnswer.setLayout(pnlAnswerLayout);
pnlAnswerLayout.setHorizontalGroup(
pnlAnswerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlAnswerLayout.createSequentialGroup()
.addComponent(lblAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
pnlAnswerLayout.setVerticalGroup(
pnlAnswerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlAnswerLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(lblAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
);
btnConvert.setBackground(new java.awt.Color(204, 0, 0));
btnConvert.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnConvert.setForeground(new java.awt.Color(0, 204, 0));
btnConvert.setText("Convert");
btnConvert.setActionCommand("Convert To");
btnConvert.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnConvertActionPerformed(evt);
}
});
comboBoxFrom.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Choose One..", "Length Units", "Time Units" }));
comboBoxFrom.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboBoxFromActionPerformed(evt);
}
});
comboBoxTo.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Choose One..", " " }));
comboBoxTo.setToolTipText("");
comboBoxTo.setEnabled(false);
comboBoxTo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboBoxToActionPerformed(evt);
}
});
txtField1.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
txtField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtField1ActionPerformed(evt);
}
});
btnReset.setBackground(new java.awt.Color(0, 204, 0));
btnReset.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnReset.setForeground(new java.awt.Color(204, 0, 0));
btnReset.setText("Reset");
btnReset.setActionCommand("Convert To");
btnReset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnResetActionPerformed(evt);
}
});
btnExit.setBackground(new java.awt.Color(0, 0, 204));
btnExit.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
btnExit.setForeground(new java.awt.Color(204, 0, 0));
btnExit.setText("Exit");
btnExit.setActionCommand("Convert To");
btnExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnExitActionPerformed(evt);
}
});
lblConvertTo.setFont(new java.awt.Font("Copperplate Gothic Light", 1, 14)); // NOI18N
lblConvertTo.setForeground(new java.awt.Color(255, 153, 0));
lblConvertTo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lblConvertTo.setText("Convert to");
lblConvertTo.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
lblConvertFrom.setFont(new java.awt.Font("Copperplate Gothic Light", 1, 14)); // NOI18N
lblConvertFrom.setForeground(new java.awt.Color(255, 153, 0));
lblConvertFrom.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
lblConvertFrom.setText(" Convert From");
lblConvertFrom.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(266, 266, 266)
.addComponent(btnExit))
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnConvert)
.addGap(45, 45, 45)
.addComponent(btnReset)
.addGap(196, 196, 196))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(pnlAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboBoxTo, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(lblConvertTo, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(lblConvertFrom, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(txtField1, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboBoxFrom, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblConvertFrom)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(comboBoxFrom, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtField1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnConvert)
.addComponent(btnReset)
.addComponent(btnExit))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(pnlAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblConvertTo))
.addComponent(comboBoxTo, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(98, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnConvertActionPerformed(java.awt.event.ActionEvent evt) {
String userInput = txtField1.getText(); //userInput equals to whatever the user typed in txtField1
}
private void comboBoxFromActionPerformed(java.awt.event.ActionEvent evt) {
String lengthUnits[] = {"Centimeters", "Feet", "Inches", "Kilometers", "Light Years", "Miles", "Meters", "Yards" }; //makes an array called lengthUnits then populates it
String timeUnits[] = {"Hours", "Milliseconds", "Minutes", "Seconds"};
if(comboBoxFrom.getSelectedItem().equals("Length Units")){
comboBoxTo.setEnabled(true); //set the comboBoxTo to be activated
comboBoxFrom.setModel(new DefaultComboBoxModel(lengthUnits));
comboBoxTo.setModel(new DefaultComboBoxModel(lengthUnits));
lengthConversion();
}
else if(comboBoxFrom.getSelectedItem().equals("Time Units")){
comboBoxTo.setEnabled(true); //set the comboBoxTo to be activated
//DefaultComboBoxModel time = new DefaultComboBoxModel(timeUnits); //makes a new model and fills it from the array timeUnits and will link the 2 comboBox's
comboBoxFrom.setModel(new DefaultComboBoxModel(timeUnits)); //also makes a new model and fills it from the array timeUnits
comboBoxTo.setModel(new DefaultComboBoxModel(timeUnits)); //but doesn't link the oomboBox's
if(comboBoxFrom.getModel().getSelectedItem().equals("Length Untis")){
lengthConversion();
}
}
}
private void comboBoxToActionPerformed(java.awt.event.ActionEvent evt) {
}
private void txtField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
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(v4Converter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(v4Converter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(v4Converter.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(v4Converter.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 v4Converter().setVisible(true);
}
});
}
private static javax.swing.JButton btnConvert;
private static javax.swing.JButton btnExit;
private static javax.swing.JButton btnReset;
private static javax.swing.JComboBox<String> comboBoxFrom;
private static javax.swing.JComboBox<String> comboBoxTo;
private static javax.swing.JLabel lblAnswer;
private javax.swing.JLabel lblConvertFrom;
private javax.swing.JLabel lblConvertTo;
private javax.swing.JPanel pnlAnswer;
static javax.swing.JTextField txtField1;
private static void lengthConversion(){
String userInput = txtField1.getText(); //userInput equals to whatever the user typed in txtField1
try{
Double.parseDouble(userInput); //checks to see if the userInput from the txtField1 is an integer if not the catch takes control
if(comboBoxFrom.getSelectedItem().equals(comboBoxTo.getSelectedItem())){
JOptionPane.showMessageDialog(null, "Cannot convert to the same unit type.", "Um, You Forgot Something!!", JOptionPane.INFORMATION_MESSAGE);
return;
}
for(String s: LENGTH_UNIT){
if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Centimeters")){
double answer = (Double.parseDouble(userInput) * TO_CENTM[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Feet")){
double answer = (Double.parseDouble(userInput) * TO_FEET[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Inches")){
double answer = (Double.parseDouble(userInput) * TO_INCHE[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Kilometers")){
double answer = (Double.parseDouble(userInput) * TO_KILOM[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Miles")){
double answer = (Double.parseDouble(userInput) * TO_MILE[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Millimeters")){
double answer = (Double.parseDouble(userInput) * TO_MILIM[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Meters")){
double answer = (Double.parseDouble(userInput) * TO_METER[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Yards")){
double answer = (Double.parseDouble(userInput) * TO_YARD[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
}
}
catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "You must type a Number", "HEY IDIOT!!", JOptionPane.INFORMATION_MESSAGE);
}
return;
}
private static void timeConversion(){
String userInput = txtField1.getText(); //userInput equals to whatever the user typed in txtField1
try{
Double.parseDouble(userInput); //checks to see if the userInput from the txtField1 is an integer if not the catch takes control
if(comboBoxFrom.getSelectedItem().equals(comboBoxTo.getSelectedItem())){
JOptionPane.showMessageDialog(null, "Cannot convert to the same unit type.", "Um, You Forgot Something!!", JOptionPane.INFORMATION_MESSAGE);
return;
}
for(String s: TIME_UNIT){
if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Days")){
double answer = (Double.parseDouble(userInput) * TO_DAY[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer))); //if answer is even
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer))); //if answer is odd
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Hours")){
double answer = (Double.parseDouble(userInput) * TO_HOUR[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Milliseconds")){
double answer = (Double.parseDouble(userInput) * TO_MILLIS[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Minutes")){
double answer = (Double.parseDouble(userInput) * TO_MINUTE[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Month")){
double answer = (Double.parseDouble(userInput) * TO_MONTH[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Seconds")){
double answer = (Double.parseDouble(userInput) * TO_SECONDS[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Week")){
double answer = (Double.parseDouble(userInput) * TO_WEEK[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
else if((comboBoxFrom.getSelectedItem().equals(s)) && comboBoxTo.getSelectedItem().equals("Years")){
double answer = (Double.parseDouble(userInput) * TO_YEAR[comboBoxFrom.getSelectedIndex()]) ; //converts userInput into a type double then makes the unit conversion
if((answer %2) == 0){
lblAnswer.setText(String.valueOf(df1.format(answer)));
}
else{
lblAnswer.setText(String.valueOf(df2.format(answer)));
}
}
}
}
catch(NumberFormatException e){
JOptionPane.showMessageDialog(null, "You must type a Number", "HEY IDIOT!!", JOptionPane.INFORMATION_MESSAGE);
}
return;
}
}
コードが多すぎます...コード内のどの部分に問題が発生しているかを正確に特定して表示してください。誰もここに座ってあなたのすべてのコードを読むことはありません。あまりにも多く –
私が本当に取り除くことができるのは、終了ボタンとリセットボタン、およびfromとtoのラベルです。 –