//************************************************************* //Java applet // 「GrayFilterTest」 // //          作 成 者:ルート高菜    //          作成開始月:2007/2 //          最終更新月:2007/2 [TN100/J90] //************************************************************* import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.swing.*; public class GrayFilterTest extends JApplet implements ActionListener { //Eclipseの場合、シリアライズ可能クラスでこれがないと警告が出る private static final long serialVersionUID=0; // Image image; GrayFilterTestPanel panel; // JComboBox brightCombo,grayCombo; JButton changeButton,formatButton; // public void init(){ // image=getImage(getDocumentBase(),"natu03.jpg"); // JPanel panel2=new JPanel(); panel2.add(new JLabel("色調を明るく:")); panel2.add(brightCombo=new JComboBox(new String[]{"false","true"})); panel2.add(new JLabel(" グレーの割合:")); panel2.add(grayCombo=new JComboBox(new String[]{"0","10","20","30","40","50","60","70","80","90","100"})); panel2.add(changeButton=new JButton("試行")); panel2.add(formatButton=new JButton("元に戻す")); //コンテナ枠 Container cp=getContentPane(); cp.add(panel=new GrayFilterTestPanel(image),BorderLayout.CENTER); cp.add(panel2,BorderLayout.SOUTH); // changeButton.addActionListener(this); formatButton.addActionListener(this); } // public void actionPerformed(ActionEvent e) { if(e.getSource()==changeButton){ //色調 boolean bright; if(brightCombo.getSelectedIndex()==0){ bright=false; }else{ bright=true; } //割合 int gray=10*grayCombo.getSelectedIndex(); //グレースケールに変換 ImageFilter filter=new GrayFilter(bright,gray); ImageProducer producer=new FilteredImageSource(image.getSource(),filter); panel.image=createImage(producer); // repaint(); }else if(e.getSource()==formatButton){ // panel.setImage(image); // repaint(); } } }