import java.awt.*; import java.awt.event.*; import java.util.Date; import java.net.*; import java.io.*; public class Nupud2 extends Frame{ TextField kirnimi = new TextField(30); final TextField teade = new TextField("Reis toimub iga päev 18.30-9.00"); TextField paevavalik = new TextField(30); Label nimi=new Label("1. Kirjuta oma nimi:"); Label teadeLabel=new Label("Teade sinu jaoks:"); Label kuupaev=new Label("2. Millal soovid sõita:"); Button jah=new Button("3. Jah, tellin pileti!"); Scrollbar paevavalimine = new Scrollbar( Scrollbar.HORIZONTAL, 7, 2, 0, 14 ); public Nupud2(){ Panel RightPanel = new Panel(); Panel LeftPanel = new Panel(); Panel LisaPanel= new Panel(); Panel Lisa2= new Panel(); setLayout(new BorderLayout()); setFont(new Font("Helvetica", Font.PLAIN, 12)); setBackground(Color.gray); kirnimi.setEditable(true); teade.setEditable(false); paevavalik.setEditable(false); paevavalik.setText(new Date().toString()); LisaPanel.setLayout(new BorderLayout()); LisaPanel.add("Center",paevavalik); LisaPanel.add("South",paevavalimine); LisaPanel.add("North",kuupaev); Lisa2.setLayout(new BorderLayout()); Lisa2.add("Center",kirnimi); Lisa2.add("North",nimi); LeftPanel.setLayout(new BorderLayout()); LeftPanel.add("Center", LisaPanel); LeftPanel.add("South", jah); RightPanel.setLayout(new BorderLayout()); RightPanel.add("North", Lisa2); RightPanel.add("Center",teadeLabel); RightPanel.add("South", teade); add("Center",LeftPanel); add("West",RightPanel); setVisible(true); pack(); show(); kirnimi.addMouseListener( new MouseAdapter(){ public void mousePressed(MouseEvent e){ teade.setText("Eesnimi ja Perekonnanimi"); } } ); paevavalimine.addMouseListener( new MouseAdapter(){ public void mousePressed(MouseEvent e){ teade.setText("Piletit on võimalik tellida 2 nädalat ette"); } } ); paevavalik.addMouseListener( new MouseAdapter(){ public void mousePressed(MouseEvent e){ teade.setText("Kuupäeva valimiseks kasuta kerimisriba"); } } ); paevavalimine.addAdjustmentListener( new Ribakuular(paevavalimine, paevavalik) ); /* jah.addMouseListener( new MouseAdapter(){ public void mousePressed(MouseEvent ev){ try{ Failnetti.main(null); } catch(IOException ex){ ex.printStackTrace(); } } } ); */ jah.addMouseListener( new andmedNetti(this) ); String perenimi=kirnimi.getText(); String paev=paevavalik.getText(); } public int getValue(){ int paevanr=paevavalimine.getValue(); return paevanr; } public static void main(String argumendid[]){ new Nupud2(); } } class Ribakuular implements AdjustmentListener{ Scrollbar sb; TextField tf; public Ribakuular(Scrollbar usb, TextField utf){ sb=usb; tf=utf; } public void adjustmentValueChanged(AdjustmentEvent e){ tf.setText( new Date( new Date().getTime()+e.getValue()*24*60*60*1000 ).toString() ); } } class andmedNetti extends MouseAdapter{ Nupud2 n2; public andmedNetti(Nupud2 un2){ n2=un2; } public void mousePressed(MouseEvent e){ String nimi=n2.kirnimi.getText(); String paev=n2.paevavalik.getText(); try{ Socket sc=new Socket("localhost", 2345); PrintWriter valja=new PrintWriter(sc.getOutputStream(), true); valja.println(n2.getValue()); valja.println(nimi); valja.println(paev); BufferedReader sisse=new BufferedReader( new InputStreamReader(sc.getInputStream()) ); String vastus=sisse.readLine(); n2.teade.setText(vastus); valja.close(); } catch(Exception ex){ ex.printStackTrace(); } } }