亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

接口的問題

接口的問題

慕姐4675099 2015-09-15 08:06:09
package com.lzw;import java.awt.*;import javax.swing.*;public class DrawIcon implements Icon { ? ? ?private int width; private int height; ? ? ?public int getIconHeight() { // 實現getIconHeight()方法 ? ? ? ? ? return this.height; } ? ?public int getIconWidth() { // 實現getIconWidth()方法 ? ? ? ? ? return this.width; } ? ? ?public DrawIcon(int width, int height) { // 定義構造方法 ? ? ? ?this.width = width; ? ? ? ?this.height = height; } ? public void paintIcon(Component arg0, Graphics arg1, int x, int y) { ? ? ? ? ?arg1.fillOval(x, y, width, height); // 繪制一個圓形 } ? ? ?public static void main(String[] args) { ? ? ? ?DrawIcon icon = new DrawIcon(15, 15); ? ? ? ? ?JLabel j = new JLabel("測試", icon, SwingConstants.CENTER); ? ? ? ? ?JFrame jf = new JFrame(); ? ? ? ? ?Container c = jf.getContentPane(); ? ? ? ?c.add(j); ? ? ? ?jf.setSize(1000,1000); ? ? ? ?jf.setVisible(true); ? ? ? ?jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); }}程序中沒有運行icon.paintIcon();方法的語句,但是后面”JLabel j = new JLabel("測試", icon, SwingConstants.CENTER);“中,直接調用了icon,而且程序結果也直接繪出了圓形圖標,那么這里是在實例化DrawIcon類對象icon之后,系統默認自動調用并且運行了類中重寫的接口中paintIcon();方法嗎?求大神解答啊
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關注
  • 1519 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號