2016-04-23 15 views
0

これは私のTextEditorプロジェクトです。ユーザーがイメージをアップロードすると、デフォルトのイメージサイズは400x400ピクセルになります。 ExpandImageShrinkImageという2つのボタンを追加しました。 ExpandImageボタンをクリックするたびに、50ピクセルに拡大する必要があります。各クリックで画像サイズのピクセルを10%に拡大するJButton?

 image = new ImageIcon(filename); 
     icon = new ImageIcon(image.getImage().getScaledInstance(400, 400, Image.SCALE_DEFAULT)); 
     editorText.insertIcon(icon); 
     editorText.setEditable(true); 
     editorText.setFocusable(true); 



ExpandImage.addActionListener(new ActionListener(){ 
       public void actionPerformed(ActionEvent e) { 
        // do stuff here 

        // 400 += 50; 
        // 400 += 50; 

        System.out.println("You clicked me!"); 
       }   
      }); 

答えて

0
 image = new ImageIcon(filename); 
    icon = new ImageIcon(image.getImage().getScaledInstance(400, 400, Image.SCALE_DEFAULT)); 
    editorText.insertIcon(icon); 
    editorText.setEditable(true); 
    editorText.setFocusable(true); 


    int point1 = 400; 
    int point2 = 400;    

    ExpandImage.addActionListener(new ActionListener(){ 
     public void actionPerformed(ActionEvent e) { 
     point1 +=50; 
     point2 +=50; 
       image = new ImageIcon(filename); 
icon = new ImageIcon(image.getImage().getScaledInstance(point1,point2, Image.SCALE_DEFAULT)); 
// 
editorText.setIcon(null) 
// 
editorText.insertIcon(icon); 
editorText.setEditable(true); 
editorText.setFocusable(true); 


      System.out.println("You clicked me!"); 
     }   
    }); 

あなたは前の値を取得し、あなたが50で、前の値をインクリメントIAM、この場合に必要な値で、それをインクリメントする必要があります。次に新しい値でアイコンを変更するメソッドを呼び出します。あなたが出力を投稿していただければ幸いです

+0

ありがとうございました!以前の画像も表示されます。あなたはそれをクリアする方法を知っていますか? – user6042355

+0

画像アイコンを消去していますか?またはデフォルトのサイズに戻す – Priyamal

+0

私は古いイメージを取り除きたいので、私は拡大ボタンをクリックした後に2つのイメージを表示しています。 – user6042355

関連する問題