日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

201771010137 赵栋 《第十二周学习总结》

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 201771010137 赵栋 《第十二周学习总结》 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一:理論部分

1.(1) 用戶界面(User Interface)用戶與計算機系統(各種程序)交互的接口

(2)圖形用戶界面(Graphical User Interface)以圖形方式呈現的用戶界面

2.AWT:Java 的抽象窗口工具箱( Abstract WindowToolkit, AWT)包含在java.awt包中,它提供了許多用來設計GUI的組件類和容器類。

. AWT庫處理用戶界面元素的方法:把圖形元素的創建和行為委托給本地GUI工具箱進行處理。

. 應用AWT編寫依賴于本地用戶界面元素GUI會暴露出一些缺陷。例如,菜單、滾動條和文本域這些

用戶界面元素,在不同的平臺上,操作行為上存在一些微妙的差異。

3.Swing:

Swing用戶界面庫是非基于對等體的GUI工具箱。

? Swing具有更豐富并且更方便的用戶界面元素集合。

? Swing對底層平臺的依賴很少,因此與平臺相關的bug很少。

? Swing會帶來交叉平臺上的統一視覺體驗。
? Swing類庫被放在javax.swing包里。

4.AWT與Swing的關系

大部分AWT組件都有其Swing的等價組件。

? Swing組件的名字一般是在AWT組件名前面添加一個字母“J”,如:JButton,JFrame,JPanel等。

二..創建框架

1.組件:構成圖形用戶界面的元素,拿來即用用圖形表示(能在屏幕上顯示,能和用戶進行交互)

2.通常把由Component類的子類或間接子類創建的對象稱為一個組件。

3.容器:容器是Java中能容納和排列組件的組件。常用的容器是框架(Frame,JFrame)

例:Frame fra = new Frame(“這是一個窗口”);

4.添加組件:

Container類提供了一個方法add(),用來在容器類組件對象中添加其他組件。

容器本身也是一個組件,可以把一個容器添加到另一個容器里,實現容器嵌套。

5.框架(Frame)的創建:

(1)創建空框架:在Java中,常采用框架(Frame)創建初始界面,即GUI的頂層窗口。

??AWT庫中有一個基于對等體的Frame類。該類的Swing版本為JFrame,JFrame是Frame子類。

(2)框架定位與框架屬性:

定位:
—常用Component類的setLocation和setBounds方法
常用屬性
—Title:框架標題
—IconImage:框架圖標

(3)確定框架的大小:通過調用Toolkit類的方法來得到屏幕尺寸信息

6.在組件中顯示信息

在AWT中可調用add()方法把組件直接添加到AWTFrame中,在Swing中組件則添加到內容窗格里。

其中內容窗格是用來添加組件的,添加代碼如下:

Container contentPane = getContentPane();

Component c=…;contentPane.add(c);. 用戶也可以自行創建一個組件類,并在組件上進行繪制,此時需要重載paintComponent()。

用戶的自建組件也可添加到內容窗格里。

. paintComponent(Graphics g)定義在JComponent類中,該方法在窗口需要重新繪圖時(如擴大窗口或極小化窗口),被系統自動調用

.. paintComponent()方法被調用時,系統就自動產生一個Graphics類型的參數,傳遞給paintComponent方法中的參數g。

組件的激活與可見性:

public void setEnabled(boolean b):設置組件是否可被激活。
當參數b取值true時,組件可以被激活。
當參數b取值false 時,組件不可激活。
默認情況下,組件是可以被激活的。
public void setVisible(boolean b):設置組件在該容器中的可見性。
當b取值true時,組件在容器中可見。
當b取值false時,組件在容器中不可見。
除了Window型組件外,其它類型組件默認是可見的。

實驗十二??圖形程序設計

實驗時間?2018-11-14

1、實驗目的與要求

(1)?掌握Java?GUI中框架創建及屬性設置中常用類的API;

(2)?掌握Java?GUI中2D圖形繪制常用類的API;

(3)?了解Java?GUI中2D圖形中字體與顏色的設置方法;

(4)?了解Java?GUI中2D圖像的載入方法。

2、實驗內容和步驟

實驗1:?導入第10章示例程序,測試程序并進行代碼注釋。

測試程序1:

l?運行下列程序,觀察程序運行結果。

?

import?javax.swing.*;

public?class?SimpleFrameTest

{

???public?static?void?main(String[]?args)

???{

?????JFrame??frame?=?new?JFrame();?

?????frame.setBounds(0,?0,300,?200);

?????frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

?????frame.setVisible(true);????

???}

}

l?在elipse?IDE中調試運行教材407頁程序10-1,結合程序運行結果理解程序;與上面程序對比,思考異同;

import java.awt.*; import javax.swing.*;/*** @version 1.33 2015-05-12* @author Cay Horstmann*/ public class SimpleFrameTest {public static void main(String[] args){EventQueue.invokeLater(() ->{SimpleFrame frame = new SimpleFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);});} }class SimpleFrame extends JFrame {private static final int DEFAULT_WIDTH = 300;private static final int DEFAULT_HEIGHT = 200;public SimpleFrame(){setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);} }

l?掌握空框架創建方法;

l?了解主線程與事件分派線程概念;

l?掌握GUI頂層窗口創建技術。

測試程序2:

l?在elipse?IDE中調試運行教材412頁程序10-2,結合程序運行結果理解程序;

import java.awt.*; import javax.swing.*;/*** @version 1.34 2015-06-16* @author Cay Horstmann*/ public class SizedFrameTest {public static void main(String[] args){EventQueue.invokeLater(() ->{JFrame frame = new SizedFrame();frame.setTitle("SizedFrame");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);});} }class SizedFrame extends JFrame {public SizedFrame(){// get screen dimensionsToolkit kit = Toolkit.getDefaultToolkit();Dimension screenSize = kit.getScreenSize();int screenHeight = screenSize.height;int screenWidth = screenSize.width;// set frame width, height and let platform pick screen locationsetSize(screenWidth / 2, screenHeight / 2);setLocationByPlatform(true);// set frame iconImage img = new ImageIcon("icon.gif").getImage();setIconImage(img); } }

l?掌握確定框架常用屬性的設置方法。

測試程序3:

l?在elipse?IDE中調試運行教材418頁程序10-3,結合運行結果理解程序;

l?掌握在框架中添加組件;

l?掌握自定義組件的用法。

測試程序4:

l?在elipse?IDE中調試運行教材424?-425頁程序10-4,結合程序運行結果理解程序;

import java.awt.*; import javax.swing.*;/*** @version 1.34 2015-06-16* @author Cay Horstmann*/ public class SizedFrameTest {public static void main(String[] args){EventQueue.invokeLater(() ->{JFrame frame = new SizedFrame();frame.setTitle("SizedFrame");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);});} }class SizedFrame extends JFrame {public SizedFrame(){// get screen dimensionsToolkit kit = Toolkit.getDefaultToolkit();Dimension screenSize = kit.getScreenSize();int screenHeight = screenSize.height;int screenWidth = screenSize.width;// set frame width, height and let platform pick screen locationsetSize(screenWidth / 2, screenHeight / 2);setLocationByPlatform(true);// set frame iconImage img = new ImageIcon("icon.gif").getImage();setIconImage(img); } }

l?掌握2D圖形的繪制方法。

測試程序5:

l?在elipse?IDE中調試運行教材432頁-433程序10-5,結合程序運行結果理解程序;

import java.awt.*; import java.awt.font.*; import java.awt.geom.*; import javax.swing.*;/*** @version 1.34 2015-05-12* @author Cay Horstmann*/ public class FontTest {public static void main(String[] args){EventQueue.invokeLater(() ->{JFrame frame = new FontFrame();frame.setTitle("FontTest");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);});} }/*** A frame with a text message component*/ class FontFrame extends JFrame {public FontFrame(){ add(new FontComponent());pack();} }/*** A component that shows a centered message in a box.*/ class FontComponent extends JComponent {private static final int DEFAULT_WIDTH = 300;private static final int DEFAULT_HEIGHT = 200;public void paintComponent(Graphics g){Graphics2D g2 = (Graphics2D) g;String message = "Hello, World!";Font f = new Font("Serif", Font.BOLD, 36);g2.setFont(f);// measure the size of the messageFontRenderContext context = g2.getFontRenderContext();Rectangle2D bounds = f.getStringBounds(message, context);// set (x,y) = top left corner of textdouble x = (getWidth() - bounds.getWidth()) / 2;double y = (getHeight() - bounds.getHeight()) / 2;// add ascent to y to reach the baselinedouble ascent = -bounds.getY();double baseY = y + ascent;// draw the messageg2.drawString(message, (int) x, (int) baseY);g2.setPaint(Color.LIGHT_GRAY);// draw the baselineg2.draw(new Line2D.Double(x, baseY, x + bounds.getWidth(), baseY));// draw the enclosing rectangleRectangle2D rect = new Rectangle2D.Double(x, y, bounds.getWidth(), bounds.getHeight());g2.draw(rect);}public Dimension getPreferredSize() { return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT); } }

l?了解2D圖形中字體的設置的方法;

測試程序6:

l?在elipse?IDE中調試運行教材436頁-437程序10-6,結合程序運行結果理解程序;

l?了解2D圖形圖像的顯示方法。

import java.awt.*; import javax.swing.*;/*** @version 1.34 2015-05-12* @author Cay Horstmann*/ public class ImageTest {public static void main(String[] args){EventQueue.invokeLater(() ->{JFrame frame = new ImageFrame();frame.setTitle("ImageTest");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);});} }/*** A frame with an image component*/ class ImageFrame extends JFrame {public ImageFrame(){add(new ImageComponent());pack();} }/*** A component that displays a tiled image*/ class ImageComponent extends JComponent {private static final int DEFAULT_WIDTH = 300;private static final int DEFAULT_HEIGHT = 200;private Image image;public ImageComponent(){image = new ImageIcon("book.jpg.jpg").getImage();}public void paintComponent(Graphics g){if (image == null) return;int imageWidth = image.getWidth(null);int imageHeight = image.getHeight(null);// draw the image in the upper-left cornerg.drawImage(image, 0, 0, null);// tile the image across the componentfor (int i = 0; i * imageWidth <= getWidth(); i++)for (int j = 0; j * imageHeight <= getHeight(); j++)if (i + j > 0) g.copyArea(0, 0, imageWidth, imageHeight, i * imageWidth, j * imageHeight);}public Dimension getPreferredSize() { return new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT); } }

?

?

?實驗總結:掌握了Java GUI中框架創建及屬性設置中常用類的API、Java GUI中2D圖形繪制常用類的API;?了解了Java GUI中2D圖形中字體與顏色的設置方法以及Java GUI中2D圖像的載入方法。在老師與學長的演示講解之下也熟悉了這章所要學習的的新知識,通過在實驗平臺上也對與以前的知識有所回顧。

?

轉載于:https://www.cnblogs.com/zd0421/p/9978243.html

總結

以上是生活随笔為你收集整理的201771010137 赵栋 《第十二周学习总结》的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。