1. 設計一個困形用戶界面。界面中包括三個標簽、三個文本框和一個按鈕。三個標
簽分別是[數學][英語][總分]按鈕的標題為[求和]要求在文本框中輸入數學、
英語分數,單擊求和按鈕后在文本框中顯示總分。
跪求跪求謝謝謝
uj5u.com熱心網友回復:
啥叫困型用戶界面uj5u.com熱心網友回復:
圖形用戶。。。。我打字錯了。。。。。
uj5u.com熱心網友回復:
<div><label>數學:</label><input type="text" id="sx">
<label>英語:</label><input type="text" id="yy">
<label>總分:</label><input type="text" id="sum">
<button onclick="sum()">求和</button>
</div>
<script>
function sum() {
var sx = document.getElementById('sx').value;//獲取數學分數
var yy = document.getElementById('yy').value;//獲取英語分數
document.getElementById('sum').value = parseInt(sx)+parseInt(yy);//將數學和英語成績總和賦值到總分
}
</script>
uj5u.com熱心網友回復:
請問這這這是java語言嗎。。。。。我是小白。。。我看不太懂
uj5u.com熱心網友回復:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class SummationForm extends JFrame implements ActionListener {
private static final long serialVersionUID = -3059616600875760053L;
JLabel labMathematics, labEnglish, labTotal;
JTextField textMathematics, textEnglish, textTotal;
static JButton butSummation;
public SummationForm() {
labMathematics = new JLabel("數學分數");
labEnglish = new JLabel("英語分數");
labTotal = new JLabel("總分");
textMathematics = new JTextField("", 10);
textEnglish = new JTextField("", 10);
textTotal = new JTextField("", 10);
butSummation = new JButton("求和");
labMathematics.setBounds(30, 30, 120, 30);
textMathematics.setBounds(180, 30, 120, 30);
labEnglish.setBounds(30, 80, 120, 30);
textEnglish.setBounds(180, 80, 120, 30);
labTotal.setBounds(30, 130, 120, 30);
textTotal.setBounds(180, 130, 120, 30);
butSummation.setBounds(160, 180, 80, 30);
add(labMathematics);
add(textMathematics);
add(labEnglish);
add(textEnglish);
add(labTotal);
add(textTotal);
add(butSummation);
setLayout(null);
setBounds(200, 100, 400, 300);
// 視窗在螢屏中間顯示
setLocationRelativeTo(null);
setTitle("求和");
setResizable(false);
setVisible(true);
}
public static void main(String[] args) {
SummationForm summationForm = new SummationForm();
butSummation.addActionListener(summationForm);
summationForm.add(butSummation);
}
public void actionPerformed(ActionEvent e) {
JButton jb = (JButton) e.getSource();
if (jb == butSummation) {
String Mathematics = textMathematics.getText();
String English = textEnglish.getText();
try {
int a = Integer.parseInt(Mathematics);
int b = Integer.parseInt(English);
int t = a + b;
textTotal.setText(String.valueOf(t));
} catch (Exception e2) {
JOptionPane.showMessageDialog(this, "輸入的分數格式錯誤!", "提示對話框", JOptionPane.DEFAULT_OPTION);
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/47778.html
標籤:Eclipse
