-1
我有一個快速的問題,我有這個代碼來計算貨幣收入和支出(對於一個企業),我已經使用了JOptionPane,這個對話框顯示對話框,我希望它顯示所有的它在一個屏幕/對話框中,我必須使用JFrame,有沒有什麼辦法可以編輯和轉換項目到JFrame,而無需再次編碼整個事情? 我的代碼:從JOptionPane更改爲JFrame
import javax.swing.JOptionPane;
public class expense_calc {
public static void main(String[] args) {
// COUNTED MONEY
int yes_no = JOptionPane.showConfirmDialog(null,
"Have you counted the 150,000/=?", "User Input",
JOptionPane.YES_NO_OPTION);
if (yes_no == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(null, "Continue!");
} else {
JOptionPane.showMessageDialog(null, "Count it First!");
System.exit(0);
}
String tenthousand = JOptionPane.showInputDialog(null,
"Enter the full 10,000/= note bundles you counted: ",
"User Input", JOptionPane.QUESTION_MESSAGE);
int ten_thousand = Integer.parseInt(tenthousand);
JOptionPane
.showMessageDialog(null,
"The amount of 10,000/= bundles you counted is "
+ ten_thousand + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
String fivethousand = JOptionPane.showInputDialog(null,
"Enter the full 5,000/= note bundles you counted: ",
"User Input", JOptionPane.QUESTION_MESSAGE);
int five_thousand = Integer.parseInt(fivethousand);
JOptionPane
.showMessageDialog(null,
"The amount of 5,000/= bundles you counted is "
+ five_thousand + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
String extraten = JOptionPane.showInputDialog(null,
"Enter the extra 10,000/= notes you counted: ", "User Input",
JOptionPane.QUESTION_MESSAGE);
int extra_ten = Integer.parseInt(extraten);
JOptionPane.showMessageDialog(null,
"The amount of extra 10,000/= notes you counted is "
+ extra_ten + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
String extrafive = JOptionPane.showInputDialog(null,
"Enter the extra 5000/= notes you counted: ", "User Input",
JOptionPane.QUESTION_MESSAGE);
int extra_five = Integer.parseInt(extrafive);
JOptionPane.showMessageDialog(null,
"The amount of extra 5,000/= notes you counted is "
+ extra_five + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
String dollars = JOptionPane.showInputDialog(null,
"Enter the amount of US Dollar you counted: ", "User Input",
JOptionPane.QUESTION_MESSAGE);
int usd = Integer.parseInt(dollars);
String usdrate = JOptionPane.showInputDialog(null,
"Enter the dollar rate: ", "User Input",
JOptionPane.QUESTION_MESSAGE);
int usd_rate = Integer.parseInt(usdrate);
JOptionPane.showMessageDialog(null,
"The converted amount of usd in tsh you counted is "
+ (usd * usd_rate) + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
// EXPENSES
String lunchmoney = JOptionPane.showInputDialog(null,
"Enter the lunch expenses: ", "User Input",
JOptionPane.QUESTION_MESSAGE);
int lunch = Integer.parseInt(lunchmoney);
JOptionPane
.showMessageDialog(null, "The amount given on lunch is "
+ lunch + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
String otherexpense = JOptionPane.showInputDialog(null,
"Enter other expenses: ", "User Input",
JOptionPane.QUESTION_MESSAGE);
int other_expense = Integer.parseInt(otherexpense);
JOptionPane.showMessageDialog(null, "The amount of other expenses is "
+ other_expense + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
// TOTAL
JOptionPane
.showMessageDialog(
null,
"The total amount today is "
+ ((150000 + ten_thousand + five_thousand
+ extra_ten + extra_five + (usd * usd_rate)) - (lunch + other_expense)),
"User Message", JOptionPane.INFORMATION_MESSAGE);
}
public static void counted() {
int yes_no = JOptionPane.showConfirmDialog(null,
"Have you counted the 150,000/=?", "User Input",
JOptionPane.YES_NO_OPTION);
if (yes_no == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(null, "Continue!");
} else {
JOptionPane.showMessageDialog(null, "Count it First!");
System.exit(0);
}
String tenthousand = JOptionPane.showInputDialog(null,
"Enter the full 10,000/= notes you counted: ", "User Input",
JOptionPane.QUESTION_MESSAGE);
int ten_thousand = Integer.parseInt(tenthousand);
JOptionPane.showMessageDialog(null, "The amount you counted is "
+ ten_thousand + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
String fivethousand = JOptionPane.showInputDialog(null,
"Enter the full 5000/= notes you counted: ", "User Input",
JOptionPane.QUESTION_MESSAGE);
int five_thousand = Integer.parseInt(fivethousand);
JOptionPane.showMessageDialog(null, "The amount you counted is "
+ five_thousand + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
String extraten = JOptionPane.showInputDialog(null,
"Enter the extra 10,000/= notes you counted: ", "User Input",
JOptionPane.QUESTION_MESSAGE);
int extra_ten = Integer.parseInt(extraten);
JOptionPane.showMessageDialog(null, "The amount you counted is "
+ extra_ten + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
String extrafive = JOptionPane.showInputDialog(null,
"Enter the extra 5000/= notes you counted: ", "User Input",
JOptionPane.QUESTION_MESSAGE);
int extra_five = Integer.parseInt(extrafive);
JOptionPane.showMessageDialog(null, "The amount you counted is "
+ extra_five + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
String extranotes = JOptionPane.showInputDialog(null,
"Enter the extra notes you counted: ", "User Input",
JOptionPane.QUESTION_MESSAGE);
int extra_notes = Integer.parseInt(extranotes);
JOptionPane.showMessageDialog(null, "The amount you counted is "
+ extra_notes + "/=", "User Message",
JOptionPane.INFORMATION_MESSAGE);
}
}
您已爲所有內容創建了JOptionPanes。一個JFrame只需要一個自己的實例,它爲所有事物保存一個範圍。您將不得不取出JOptionPanes並將佈局應用於JFrame以獲得預期的結果。 –