a sample on what you can do with paint and draw

johnroach1985 0 Tallied Votes 142 Views Share

Hope you like it 8)

import java.awt.*;
import java.awt.event.*;

public class asd{
public static void main(String args[]){
Pencere pen=new Pencere();
pen.setVisible(true);

}

} 

class Pencere extends Frame{
Choice c1;
Choice c2;
public Pencere(){
setTitle("Ornek");
setSize(300,300);
this.setLayout(new FlowLayout());
c1=new Choice();
c1.addItem("red");
c1.addItem("green");
c1.addItem("blue");
c2=new Choice();
c2.addItem("red");
c2.addItem("green");
c2.addItem("blue");
Button b=new Button("ciz");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
repaint();//paint direct cagrilmaz repaint gerekir
}

});

add(c1);
add(c2);
add(b);

}


String []rr={"0xff0000","0x00ff00","0x0000ff"};
public void paint(Graphics g){
Color col1=Color.decode(rr[c2.getSelectedIndex()]);
g.setColor(col1);
g.fillRect(100,100,255,100);
String str="0xff0000";
Color.getColor(str,100);

int bir=0,iki=0,uc=0;
int secili=c1.getSelectedIndex();
switch(secili){
case 0:bir=255;break;
case 1:iki=255;break;
case 2:uc=255;break;
}

for (int i = 0; i<255; i++) {
g.setColor(new Color(bir,iki,uc,255-i));
g.drawLine(100+i,100,100+i,200);
}

} 
}
/*
__________________
------

"A rational anachist believes that concepts such as 'state' and 'society' and 'government' have no existence save as physically exemplified in acts of self-responsible individuals.He believese that it is impossible to shift blame,share blame,distrubute blame.... as blame,guilt,responsibility are matters taking place inside human beings singly and nowhere else.But being rational,he knows that not all individuals hold his evaluations,so he tries to live perfectly in an imperfectworld...aware that his effort wil be less than perfect yet undismayed by self-knowledge of self-failure."

-Robert A. Heinlein

-----
John Roach 
*/
ksunni 0 Newbie Poster

the code looks fine with some nice touches..
i liked the quote at the end - alas man!

mmiikkee12 1 Posting Whiz in Training

Yeah... but put it in a comment... I accidentally copied that part too and it had a compile problem...

Dani 4,310 The Queen of DaniWeb Administrator Featured Poster Premium Member

Quote in the end commented out :)

cms271828 2 Junior Poster

Nice program, but not very fun.
If you could make some mad coloured images that would be more fun.
Still good though, does what it says on the tin!

sciwizeh 62 Posting Pro in Training

somewhere there needs to be the line: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.