計算成績代碼

來源:互聯網
上載者:User

標籤:

package j;

import java.awt.Frame;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class j {

public static void main(String[] args) 
{

Frame f=new Frame();
f.setLayout(null);//自由布局
f.setTitle("成績判定");//設定標題
f.setSize(586, 540);//調整大小
f.setLocation(100, 100);//設定視窗位置
JLabel l1=new JLabel("成績");
l1.setBounds(200, 150, 50, 50);
f.add(l1);
JTextField t=new JTextField("請輸入成績");
t.setBounds(300, 160, 100, 30);
f.add(t);
JButton b1=new JButton("確定");
JButton b2=new JButton("取消");
b1.setBounds(200,230,80,30);
f.add(b1);
b2.setBounds(320,230,80,30);
f.add(b2);
t.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
t.setText("");}
});
b1.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) 
{
String s;
s=t.getText();
try 
{
int a = 0;
a= Integer.parseInt(s);
if(a<60&&a>=0)
{
JOptionPane.showMessageDialog(null, "不及格");
}
else if(a<70&&a>=0)
{
JOptionPane.showMessageDialog(null, "及格");
}
else if(a<80&&a>=0)
{
JOptionPane.showMessageDialog(null, "中");
}
else if(a<90&&a>=0)
{
JOptionPane.showMessageDialog(null, "良");
}
else if(a<=100&&a>=0)
{
JOptionPane.showMessageDialog(null, "優");
}
else 
{
JOptionPane.showMessageDialog(null, "輸入錯誤");
}
}
catch (NumberFormatException e1) 
{

JOptionPane.showMessageDialog(null, "輸入錯誤");
}

}
});
b2.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) 
{

System.exit(0);
}
});
f.addWindowListener
(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
Icon i1 = new ImageIcon("2.jpg");

JLabel bg=new JLabel(i1);
bg.setBounds(0,0, 586,540);
f.add(bg);
f.setVisible(true);//顯示視窗


}
}

計算成績代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.