import java.awt.*; import java.awt.event.*; import java.io.*; import java.awt.print.*; import java.util.Date; import java.net.*; public class Ruhmatoo1a extends Frame implements ActionListener{ Panel alus=new Panel(); Panel nupu=new Panel(); //loob m'llu Panel p2=new Panel(); Button b=new Button("Save"); Frame f=new Frame(); String[] reisiandmed={"Koht", "Sihtpunkt", "Hind", "Ostuaeg", "Reisi algus"}; Label [] s1=new Label[5]; TextField[] v1=new TextField[5]; Checkbox[] c1=new Checkbox[16]; String[] k={"1", "5", "9", "13", "2", "6", "10", "14", "3", "7", "11", "15", "4", "8", "12", "16"}; public Ruhmatoo1a(){ b.addActionListener(this); //kuular nupule alus.setLayout(new GridLayout(5,2)); for(int i=0;i<5;i++){ //esimesse paneeli sildid s1 [i]=new Label(reisiandmed[i]); alus.add(s1[i]); v1 [i]=new TextField(); //ja tekstiv'ljad alus.add(v1[i]); } v1[3].setText(new Date().toString()); //kuup'ev tekstiv'lja v1[4].setText("17.00"); //bussi v'ljumise aeg p2.setLayout(new GridLayout(4,4)); for(int i=0; i<16; i++){ //loob graafiliselt bussiistekohad c1 [i]=new Checkbox(k[i]); p2.add(c1[i]); } f.setSize(220, 180); f.setLocation(300, 150); //loob piletiraami f.setVisible(true); setLayout(new GridLayout(3,2)); add(alus); add(p2); nupu.add(b); //paneb paneelid ekraanile add(nupu); } public void actionPerformed(ActionEvent e){ try{ //nupu vajutuse korral kirjutab PrintWriter faili=new PrintWriter( //faili istekoha numbri new FileWriter("Ruhmatoo2.java", true)); faili.println("Koht: "+v1[0].getText()); faili.println("Hind: "+v1[2].getText()); faili.close(); System.out.println("Koht:"+v1[0].getText()); System.out.println("Hind:"+v1[2].getText()); Socket sc=new Socket("localhost", 3002); //votab uhendust teise arvutiga PrintWriter va=new PrintWriter(sc.getOutputStream(), true); va.println("Koht:"+v1[0].getText()); va.println(" Hind:"+v1[2].getText()); } catch(Exception ex){ System.out.println("Probleem"+ex); } Graphics g=f.getGraphics(); //kujundus piletile g.setColor(Color.black); g.drawRect(10, 60, 200, 100); //joonistab raami g.drawString("Koht:"+" "+v1[0].getText(),20, 80); //paneb kirjad g.drawString("Sihtpunkt:"+" "+v1[1].getText(), 20, 100); g.drawString("Valjub:"+" "+v1[4].getText(), 20, 120); g.drawString("Kuupaev:"+" "+v1[3].getText(), 20, 140); v1[0].setText(" "); v1[1].setText(" "); //puhastab tekstiv'ljad v1[2].setText(" "); } public static void main(String argumendid[]) throws Exception{ Frame f=new Ruhmatoo1a(); f.setSize(300,290); //loob paneelidega raami f.setVisible(true); ServerSocket ss=new ServerSocket(3001); while(true){ //uhendus, kui teine new Ruhmatoo1aloim(ss.accept()); // uhendust votab } } } class Ruhmatoo1aloim extends Thread{ Socket sc; public Ruhmatoo1aloim(Socket uus_sc) { //loim, et mitu saaks sc=uus_sc; // korraga uhendust votta start(); } public void run(){ //kui keegi uhebdust votab, siis loeb, mis try{ //kirjutati BufferedReader sisse=new BufferedReader( new InputStreamReader(sc.getInputStream())); String rida=" "; while((rida=sisse.readLine())!=null)System.out.println(rida); sc.close(); }catch(Exception ex){ System.out.println(ex); } } }