Verifica

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;
    }

    public void setColore2(Color c2){
        colore2= c2;
    }
    public void paintComponent(Graphics g){
        g.setColor(colore1);
        g.fillOval(0,50,200,200);
        g.setColor(colore2);
        g.fillOval(50,100,100,100);
        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;
    }
    public int nascondi(int d){
        y=d;
        return y;
    }
    public int mostra(){
        a=1;
        return a;
    }
}

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

import java.io.*;
import java.net.*;
public class ServerSemplice {
    public void go(){
        try{
            ServerSocket s1=new ServerSocket(12);//mi creo una porta di ascolto
            while(true){    //quando qualcuno chiede di entrare creo un collegamento diretto tra server e client
                Socket presa=s1.accept(); //il socket è una presa
                //trasmissione dei dati al client:
                PrintWriter scrivi=new PrintWriter(presa.getOutputStream());//classe che invia i dati nel collegamento virtuale
                int s=getSuggerimenti();
                scrivi.println(s);//manda nel canale la stringa s
                scrivi.close();
                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.*;
public class TestaDueCerchi {
    int y;
    BufferedReader lettore;
    Socket sock;
    PrintWriter scrittore;
    JFrame f1=new JFrame("disegno1");
    DueCerchi d1=new DueCerchi();
    JButton b=new JButton("Ricevi");
    JPanel p1=new JPanel();
    JButton nascondi=new JButton("Nascondi");
    JButton mostra=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 Bottone());
        JFrame f1=new JFrame("Gioco chat");
          f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          a1=new JTextArea(20,50);
          t1=new JTextField(200);
          JButton b1=new JButton("invia il messaggio");
          b.addActionListener(new Bottone());
          nascondi.addActionListener(new Nascondi());
          p1.setLayout(new GridLayout(2,3));
          scrollPane= new JScrollPane(a1);
          p1.add(scrollPane, BorderLayout.CENTER);
          p1.add(t1);
          p1.add(b1);
          p1.add(BorderLayout.SOUTH,d1);
          p1.add(nascondi);
          p1.add(b);
          f1.add(BorderLayout.SOUTH,mostra );
          mostra.addActionListener(new Mostra());
          f1.add(p1);
          f1.pack();
          f1.setVisible(true);
        }
    public class Bottone implements ActionListener{
            public void actionPerformed(ActionEvent e){
                go();
                p1.repaint();
            }
    }
    public class Nascondi implements ActionListener{
        public void actionPerformed(ActionEvent e){
            d1.nascondi(33);
            p1.repaint();
        }
    }
    public class Mostra implements ActionListener{
        public void actionPerformed(ActionEvent e){
            d1.mostra();
            p1.repaint();
        }
    }

    public void go(){
        try{
            //collegamento al server(ip,porta)
            for(int i=0;i<1;i++){
            Socket s=new Socket("localhost",12);
            InputStreamReader r=new InputStreamReader(s.getInputStream());
            BufferedReader reader=new BufferedReader(r);
            //istruzione per leggere dal server
            String suggerimento=reader.readLine();
            System.out.println("Suggerimento: "+suggerimento);
            y=Integer.parseInt(suggerimento);
            d1.getY(y);
            reader.close();
            }
        }catch(IOException ex){
            ex.printStackTrace();
        }
    }

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

 

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

clip_image002

Commenti