Wednesday, March 24, 2010

Silent Auction Basket




import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
public class DueCerchi extends JPanel{
    Color colore1=Color.YELLOW;
    Color colore2=Color.RED;
    String numero="";
    String n="";
    int y;
    int a;
    int[][]coord={{110, 80},{150, 100},{170, 130},{170, 170},{150, 210},{115, 230},     {80, 230},{40, 210},{10, 170},{10, 130},{30, 100},{70,80}};     public void setColore1(Color c1){         colore1=c1;
    }         colore2= c2;     }     public void paintComponent(Graphics g){         g.setColor(colore1);         g.fillOval(0,50,200,200);         g.drawLine(100,250,100,50);

        g.drawLine(0,150,200,150);
        g.drawLine(10,200,190,100);
        g.drawLine(10,100,190,200);
        g.drawLine(50,60,150,240);
        g.drawLine(50,240,150,60);
        int j;
        for(int i=0;i<12;i++){
            j=i+1;
            n=numero+j;
            g.drawString(n,coord[i][0],coord[i][1]);
            if(i==y){
                g.fillOval(coord[i][0]+5,coord[i][1],10,10);
                System.out.println("La mia y e:"+y);
            }
            if(a==1){
                g.fillOval(coord[i][0]+5,coord[i][1],10,10);
            }
        }

        a=0;

        g.setColor(colore2);
    }
    public int getY(int a){
        y=a;
        return y;}
Hide
public int (int d) {
, y = d;
return y;}

public int show () {&
# 160; a = 1;
        return a;
    }
}

---------------------------------------------------------------------

import java.io.*;
import java.net.*;
public class ServerSemplice {
    public void go(){
        try{
            S1 = new ServerSocket ServerSocket (12), / / \u200b\u200bI create a listening port
while (true) {/ / if someone asks to enter do I create a direct connection between server and client
& # 160; ; s1.accept Socket socket = (), / / \u200b\u200bthe socket is a socket
& # 160 / / broadcast data to the client:
& # 160; PrintWriter write = new PrintWriter (presa.getOutputStream ());// class that sends data in the virtual link
& # 160; getSuggerimenti int s = ();
& # 160; scrivi.println (s) / / send the string s in the channel
scrivi.close ();
& # 160; System.out.println(s);
            }
        }
        catch(IOException ex){
            ex.printStackTrace();
        }

    }
    private int getSuggerimenti(){
        double r1=Math.random()*12;
        int r=(int)r1;
        return r;

    }

    public static void main(String args[]){

        ServerSemplice serv=new ServerSemplice();

        serv.go();
    }
}

 

---------------------------------------------------------------------

import java.awt.event.*;
import java.io. *;
import java.net .*;
import java.util .*;
import javax.swing .*;
import java.awt .*;
TestaDueCerchi {public class
int y;
BufferedReader reader;
Socket sock;
& # 160; PrintWriter writer;

JFrame f1 = new JFrame ("disegno1");

DueCerchi d1 = new DueCerchi ();
JButton b = new JButton ("Ricevi");
JPanel p1 = new JPanel (); Hide
JButton = new JButton ("Hide");
mostra JButton = new JButton ("Mostra");
JTextField t1;
JTextArea a1;
JScrollPane scrollPane;
    public TestaDueCerchi(){
        f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        d1.setColore1(Color.YELLOW);

        d1.setColore2(Color.BLUE);

        f1.add(BorderLayout.SOUTH,b);

b.addActionListener (new Button ());

& # 160; JFrame f1 = new JFrame ("Game Chat");

& # 160; f1.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

& # 160; a1 = new JTextArea (20,50);
t1 = new JTextField (200);
JButton b1 = new JButton (" invia il messaggio ");
b.addActionListener (new Bottone ( ));
nascondi.addActionListener (new Hide ());
p1.setLayout (new GridLayout (2,3));
= new ScrollPane JScrollPane (a1);
p1.add (ScrollPane, BorderLayout. CENTER);
p1.add (t1);
p1.add (b1) ;
p1.add (BorderLayout.SOUTH, d1);
p1.add (hide);
& # 160; p1.add (b);
f1.add (BorderLayout. SOUTH shows);
mostra.addActionListener (new Display () );
f1.add (p1);
; f1.pack();
          f1.setVisible(true);
        }
    public class Bottone implements ActionListener{
            public void actionPerformed(ActionEvent e){
                go ();
& # 160; p1.repaint ();


}} public class Hide implements ActionListener {
public void actionPerformed(ActionEvent e){
            d1.nascondi(33);
            p1.repaint();
        }
    }
    public class View implements ActionListener {
public void actionPerformed (ActionEvent e) {
& # 160; d1.mostra ();
& # 160; p1.repaint ();



}} public void go () {# &
160; try {
& # 160 / / connect to server (ip, port)
for (int i = 0; i \u0026lt;1; i + +) {
& # 160; Socket s = new Socket ("localhost", 12);
& # 160; InputStreamReader r = new InputStreamReader (s.getInputStream ());
& # 160; BufferedReader reader = new BufferedReader (r);
/ / statement to read from the server
& # 160; reader.readLine String tip = ();
& # 160; System.out.println ("Tip: "+ Hint);
, y = Integer.parseInt (hint);
; d1.getY (y);
& # 160; reader.close ();
}
        }catch(IOException ex){
            ex.printStackTrace();
        }
    }

    public static void main(String[]args){
        TestaDueCerchi TestaDueCerchi d = new ();}

}



------------------ -------------------------------------------------- -








0 comments:

Post a Comment