View Single Post
Eski 08/12/2006, 18:03   #7 (permalink)
tosta
Üye
 
Üyelik Tarihi: 10/2006
Mesaj: 46
Varsayılan

arkadaşlar şimdi kodda butonu gayet güzel ekledim de butona her basıldığında sayıları yeniden üretip ekranda görünmesini istiyorum bunun için nasıl bir yol izlemem lazım bana yardımcı olurmusunuz.
Kod:
   import java.util.Random;
   import javax.swing.JFrame;
   import javax.swing.JPanel;
   import javax.swing.JButton; 
   import java.awt.*;
   import java.awt.event.ActionListener;
   import java.awt.event.ActionEvent;

   public class sayisalLotom2 extends JPanel 
   {
     
      private JButton button; 
      private GridBagLayout gbl;
      private GridBagConstraints gbc;
      Random myRandom=new Random();
       int a=myRandom.nextInt(48)+1;
      String i=Integer.toString(a);
      int b=myRandom.nextInt(48)+1;
      String j=Integer.toString(b); 
      int c=myRandom.nextInt(48)+1;
      String k=Integer.toString(c); 
      int d=myRandom.nextInt(48)+1;
      String l=Integer.toString(d); 
      int e=myRandom.nextInt(48)+1;
      String m=Integer.toString(e); 
      int f=myRandom.nextInt(48)+1;
      String n=Integer.toString(f); 
      public sayisalLotom2() {
        
        
        button=new JButton("OYNA");
        gbl=new GridBagLayout();
        gbc=new GridBagConstraints();
        
        setLayout(gbl);
       
       // gbc.ipady = 0;
        gbc.weightx = 2.0;
        gbc.weighty = 2.0;
        gbc.insets = new Insets(0,325,7,10);
        gbc.gridwidth = 0;
        gbc.gridx = 0;
        gbc.gridy = 0;

        gbc.fill=GridBagConstraints.HORIZONTAL;
        gbc.anchor=GridBagConstraints.LAST_LINE_END;
        gbl.setConstraints(button,gbc);
        add(button);
      
       ButtonHandler handler = new ButtonHandler();
       button.addActionListener( handler );
     }
      private class ButtonHandler implements ActionListener {
        public void actionPerformed( ActionEvent event )
        {
          
   
          
        }
      }
      public void paintComponent( Graphics g )
     {
      
        super.paintComponent( g );            
        g.setColor( Color.GREEN );    
        g.fillOval( 20, 30, 60, 60 );
        g.setColor( Color.BLUE );    
        g.fillOval( 80, 30, 60, 60 );
        g.setColor( Color.YELLOW );    
        g.fillOval( 140, 30, 60, 60 );
        g.setColor( Color.ORANGE );    
        g.fillOval( 200, 30, 60, 60 );
        g.setColor( Color.PINK );    
        g.fillOval( 260, 30, 60, 60 );
        g.setColor( Color.RED );    
        g.fillOval( 320, 30, 60, 60 );
        g.setFont(new Font("SansSerif",Font.BOLD,40) );
        if(a>=10){
        g.setColor( Color.BLACK );
        g.drawString(i,27,72);
        }
        else {
        g.setColor( Color.BLACK );
        g.drawString(i,39,72);
        }
        if(b>=10){
        g.setColor( Color.BLACK );
        g.drawString(j,87,72);
        }
        else {
        g.setColor( Color.BLACK );
        g.drawString(j,99,72);
        }
        if(c>=10){
        g.setColor( Color.BLACK );
        g.drawString(k,147,72);
        }
        else {
        g.setColor( Color.BLACK );
        g.drawString(k,159,72);
        }
        if(d>=10){
        g.setColor( Color.BLACK );
        g.drawString(l,207,72);
        }
        else {
        g.setColor( Color.BLACK );
        g.drawString(l,219,72);
        }
        if(e>=10){
        g.setColor( Color.BLACK );
        g.drawString(m,267,72);
        }
        else {
        g.setColor( Color.BLACK );
        g.drawString(m,279,72);
        }
        if(f>=10){
        g.setColor( Color.BLACK );
        g.drawString(n,327,72);
        }
        else {
        g.setColor( Color.BLACK );
        g.drawString(n,339,72);
        }
        
       }
      
     
      
      public static void main( String args[] )
      {
        sayisalLotom2 loto = new sayisalLotom2();
        JFrame application = new JFrame("Sayisal Lotom");

        application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        application.add( loto );
        application.setSize( 410, 180 );
        application.setVisible( true );
     } 
  }
tosta hatta değil   Alıntı Yaparak Yanıtla