私はこれをしばらくの間回っていました、そして私はもっと混乱しています。私が達成したいことがいくつかあります:
JTextField1に2つのラベルを追加します。最初に電子メールの入力を求めます。2つ目は、@address.comがすでに入力されていることを示します。
String変数を渡す方法がわかりません。たぶん、1つのメソッドだけが必要ですか?
import javax.swing.*; import java.awt.*; public class Email { public static void main(String[] args) { //main method //get user input JPanel panel = new JPanel(); //create new JPanel JTextField field1 = new JTextField(20); //create a field for email and show 20 characters panel.add(field1); JTextField field2 = new JTextField(6); //create a field for grade and show to 6 characters panel.add(field2); int iValue = JOptionPane.showConfirmDialog ( null, panel, "Please enter students email adress and test grade", JOptionPane.OK_OPTION); //create button in panel if (iValue == JOptionPane.OK_OPTION) { //capture email address as String String sEmail = field1.getText() + "@address.com"; //capture numerical grade input and convert it to a float float fGrade = Float.parseFloat(field2.getText()); } } //end main public void convertGrades(float fGrade) { /***"shortcut if" grade conversion*********** String sLetterGrade = (fGrade >= 97) ? "A+" : (fGrade >= 94) ? "A" : (fGrade >= 90) ? "A-" : (fGrade >= 87) ? "B+" : (fGrade >= 84) ? "B" : (fGrade >= 80) ? "B-" : (fGrade >= 77) ? "C+" : (fGrade >= 74) ? "C" : (fGrade >= 70) ? "C-" : (fGrade >= 67) ? "D+" : (fGrade >= 64) ? "D" : (fGrade >= 60) ? "D-" : "F"; *************************************************************************/ //experimental grade conversion // Determine letter grade String sAlphaGrade = (fGrade >= 90) ? "A" : (fGrade >= 80) ? "B" : (fGrade >= 70) ? "C" : (fGrade >= 60) ? "D" : "F"; //determine + or - if (fGrade >= 60) { float fGradeModifier = (fGrade % 10); String sAlphaModifier = (fGradeModifier >= 7) ? "+" : (fGradeModifier >= 4)? "" : "-"; //concatenate letter grade and modifier String sLetterGrade = sAlphaGrade + sAlphaModifier; } // end if String sResults = getInput.sEmail + "\n" + sMessage + "\n" + "your test score is: " + fGrade + "\n" + "your letter grade is: " + sLetterGrade; JOptionPane.showMessageDialog(null, sOutput,"Email and Grade", JOptionPane.INFORMATION_MESSAGE); } //end convertGrades } //end class Email