




已閱讀5頁,還剩1頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
Java與面向?qū)ο蟪绦蛟O(shè)計(jì)上機(jī)報告l 第一題:修改第五章中StyleOptions程序,允許用戶指定字體大小,用單行文本框得到字體大小。提示:參考例題5.225.23源程序:import javax.swing.*;import java.awt.*;import java.awt.event.*;public class StyleOptionsPanel extends JPanel private JLabel saying,inputLabel,resultLabel; private JCheckBox bold, italic; private JTextField num; public StyleOptionsPanel() String numStr; inputLabel=new JLabel(Font Size:); num=new JTextField(8); num.addActionListener(new TempListener(); saying = new JLabel (Say it with style!); saying.setFont (new Font (Helvetica, Font.PLAIN, 36); bold = new JCheckBox (Bold); bold.setBackground (Color.green); italic = new JCheckBox (Italic); italic.setBackground (Color.green); StyleListener listener = new StyleListener(); bold.addItemListener (listener); italic.addItemListener (listener); add (saying); add (bold); add (italic); add(inputLabel); add(num); setBackground (Color.yellow); setPreferredSize (new Dimension(300, 100); private class TempListener implements ActionListener public void actionPerformed (ActionEvent event) int number=36; String text = num.getText(); number= Integer.parseInt (text); saying.setFont (new Font (Helvetica, Font.PLAIN, number); private class StyleListener implements ItemListener public void itemStateChanged (ItemEvent event) int style = Font.PLAIN; if (bold.isSelected() style = Font.BOLD; if (italic.isSelected() style += Font.ITALIC;saying.setFont (new Font (Helvetica, style, 36); import javax.swing.JFrame;public class StyleOptions public static void main (String args) JFrame frame = new JFrame (Style Options); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); StyleOptionsPanel panel = new StyleOptionsPanel(); frame.getContentPane().add (panel); frame.pack(); frame.setVisible(true); 運(yùn)行情況及結(jié)果截圖:完成情況說明:l 第二題:PP6.1 修改第四章的Account類,使其也允許僅使用賬戶名和賬號建立賬戶,并假設(shè)初始余額為0。修改Transactions類的main方法實(shí)現(xiàn)這個新功能。提示:參考例4.34.4源程序:import java.text.NumberFormat; class Account private final double RATE = 0.035; / interest rate of 3.5% private long acctNumber; private double balance; private String name; public Account (String owner, long account, double initial) name = owner; acctNumber = account; balance = initial; public Account (String owner, long account) name = owner; acctNumber = account; balance = 0.00; public double deposit (double amount) balance = balance + amount; return balance; public double withdraw (double amount, double fee) balance = balance - amount - fee; return balance; public double addInterest () balance += (balance * RATE); return balance; public double getBalance () return balance; public String toString () NumberFormat fmt = NumberFormat.getCurrencyInstance(); return (acctNumber + t + name + t + fmt.format(balance); public class Transactions public static void main (String args) Account acct1 = new Account (Ted Murphy, 72354, 102.56); Account acct2 = new Account (Jane Smith, 69713, 40.00); Account acct3 = new Account (Edward Demsey, 93757, 759.32); Account acct4 = new Account (jhgu, 67856); acct1.deposit (25.85); double smithBalance = acct2.deposit (500.00); System.out.println (Smith balance after deposit: + smithBalance); System.out.println (Smith balance after withdrawal: + acct2.withdraw (430.75, 1.50); acct1.addInterest(); acct2.addInterest(); acct3.addInterest(); acct4.addInterest(); System.out.println (); System.out.println (acct1); System.out.println (acct2); System.out.println (acct3); System.out.pri
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 鐵道養(yǎng)路機(jī)械應(yīng)用技術(shù)專業(yè)教學(xué)標(biāo)準(zhǔn)(高等職業(yè)教育專科)2025修訂
- 藥學(xué)專業(yè)教學(xué)標(biāo)準(zhǔn)(高等職業(yè)教育??疲?025修訂
- 臨床皮內(nèi)注射技術(shù)
- 稅務(wù)師考試東奧課件
- 中國廣告發(fā)布行業(yè)市場調(diào)查研究及投資前景預(yù)測報告
- 中國農(nóng)藥殺菌劑行業(yè)市場調(diào)查報告
- 2025年中國手袋線行業(yè)市場發(fā)展前景及發(fā)展趨勢與投資戰(zhàn)略研究報告
- 回復(fù)反射器行業(yè)深度研究分析報告(2024-2030版)
- 中國城市經(jīng)營行業(yè)市場發(fā)展現(xiàn)狀及前景趨勢與投資分析研究報告(2024-2030)
- 2025年中國小曲酒行業(yè)市場深度調(diào)研分析及投資前景研究預(yù)測報告
- 第三方外包管理制度
- 2025年重慶市中考生物試卷真題(含標(biāo)準(zhǔn)答案)
- 2025高考英語解析及其范文
- 2025年6月8日北京市事業(yè)單位面試真題及答案解析(下午卷)
- 人力資源測評期末考試試題及答案
- 2024年貴州省糧食儲備集團(tuán)有限公司招聘真題
- 護(hù)理生物學(xué)試題及答案
- 電子產(chǎn)品倉庫管理制度與流程
- 浙江國企招聘2025杭州地鐵科技有限公司招聘51人(第一批)筆試參考題庫附帶答案詳解析
- 深度學(xué)習(xí)的基本概念試題及答案
- 甘肅省平?jīng)鍪?025屆七下數(shù)學(xué)期末教學(xué)質(zhì)量檢測試題含解析
評論
0/150
提交評論