線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1153
推到 Plurk!
推到 Facebook!

為何一開jColorChooser.原本畫面就會變空白

尚未結案
totol
一般會員


發表:3
回覆:2
積分:1
註冊:2003-05-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-07-13 16:19:21 IP:61.218.xxx.xxx 未訂閱
請問是不是每開一次要選顏色的...原本的圖形都會不見阿?? 因為現在在做改變畫筆顏色,不過每次只要一換顏色,原本的圖案就不見了.. 不知道原因..想請教一下大家....
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-07-14 01:04:02 IP:61.221.xxx.xxx 未訂閱
引言: 請問是不是每開一次要選顏色的...原本的圖形都會不見阿?? 因為現在在做改變畫筆顏色,不過每次只要一換顏色,原本的圖案就不見了.. 不知道原因..想請教一下大家....
totol 你好:
(1)請問?? 你的程式碼呢?? 是如何寫的呢??
( >
   >    -- 
        
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
totol
一般會員


發表:3
回覆:2
積分:1
註冊:2003-05-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-07-18 00:02:18 IP:218.162.xxx.xxx 未訂閱
我是用jbuilder寫的.. 是寫三個按鈕,一個筆,一個擦子,一個是改筆的顏色。 不過當我要按下改顏色的按鈕時,原本畫板的線條也就不見了 所以我想問的是,是不是叫出JColorChooser時,就會把畫面清除啊??? 謝謝... package test1; import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; public class Applet1 extends Applet { boolean isStandalone = false; Button button1 = new Button(); Button button2 = new Button(); final int CIRCLESIZE=20; private Point lineStart=new Point(0,0); private Graphics g; int x; Color color; JButton jButton1 = new JButton(); //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public Applet1() { } //Initialize the applet public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { button1.setLabel("筆"); button1.setBounds(new Rectangle(14, 7, 75, 41)); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); this.setLayout(null); button2.setLabel("擦"); button2.setBounds(new Rectangle(93, 7, 83, 40)); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button2_actionPerformed(e); } }); this.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(MouseEvent e) { this_mousePressed(e); } }); this.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { this_mouseDragged(e); } }); jButton1.setBounds(new Rectangle(180, 8, 75, 39)); jButton1.setText("換顏色"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); this.add(button1, null); this.add(button2, null); this.add(jButton1, null); } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { return null; } void this_mousePressed(MouseEvent e) { lineStart.move(e.getX(),e.getY()); } void this_mouseDragged(MouseEvent e) { g=getGraphics(); if(x==2) { g.setColor(getBackground()); g.fillOval(e.getX()-(CIRCLESIZE/2),e.getY()-(CIRCLESIZE/2),CIRCLESIZE,CIRCLESIZE); } if(x==1) { g.setColor(color); g.drawLine(lineStart.x,lineStart.y,e.getX(),e.getY()); } lineStart.move(e.getX(),e.getY()); g.dispose(); } void button1_actionPerformed(ActionEvent e) { x=1; } void button2_actionPerformed(ActionEvent e) { x=2; } void jButton1_actionPerformed(ActionEvent e) { color=JColorChooser.showDialog(this,"換顏色",color); if(color!=null) g.setColor(color); } }
richtop
資深會員


發表:122
回覆:646
積分:468
註冊:2003-06-10

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-09-21 01:36:49 IP:211.76.xxx.xxx 未訂閱
totol您好: 您的問題應該是:您只是把圖形暫時畫在該applet所顯示的位置上,這些畫上去的圖形並沒有成為該applet的一部分,所以即便是您將該程式先最小化,再還原其大小,可能原先您畫的東西亦將消失無蹤。 因此當您開啟對話盒時,被對話盒蓋住的部分在對話盒消失後,應該也就跟著不見了。 這是因為您在程式啟動之後,所畫的圖形,並沒有動態的加入此applet的重繪內容中,或者說當applet重繪時,根本不知道您加了多少資料,只會將原程式的初始畫面重繪出來而已。 所以如果要避免當程式被其他元件覆蓋後消失不見,就必須將新繪的內容存下來,並在重繪的程式部份paint()中,將他們畫出來。 希望對您的問題有幫助!
系統時間:2024-05-20 7:12:26
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!