import java.awt.*; import java.sql.*; import java.io.*; import java.applet.*; import java.awt.event.*; public class Raam{ public static void main(String argumendid[]) throws Exception{ new Raamise(); BufferedReader sisse=new BufferedReader( new InputStreamReader(System.in) ); } } //raam class Raamise extends Frame implements ItemListener{ Choice valik=new Choice(); public Raamise(){ setLayout(new FlowLayout()); setSize(300, 300); valik.add("aadressid"); valik.add("märksõnad"); valik.add("ühendused"); valik.addItemListener(this); add(valik); setVisible(true); addWindowListener(new Raamikuular()); } public void paint(Graphics p){ try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn=DriverManager.getConnection("jdbc:odbc:baas1", "", ""); Statement st=cn.createStatement(); //käib, loeb ab-s kokku, palju kirjeid on ja siis joonistab nende põhjal pildi if(valik.getSelectedItem().equals("aadressid")){ p.setColor(Color.red); ResultSet aadr=st.executeQuery("SELECT count(*) as a FROM aadress"); aadr.next(); p.fillRect(125, 100, 50, aadr.getInt("a")*10); } if(valik.getSelectedItem().equals("märksõnad")){ p.setColor(Color.green); ResultSet marks=st.executeQuery("SELECT count(*) as m FROM marksonad"); marks.next(); p.fillRect(125, 100, 50, marks.getInt("m")*10); } if(valik.getSelectedItem().equals("ühendused")){ p.setColor(Color.blue); ResultSet yhend=st.executeQuery("SELECT count(*) as y FROM yhend"); yhend.next(); p.fillRect(125, 100, 50, yhend.getInt("y")*10); } } catch(Exception e) { System.out.println("Miskit viga: "+e.getMessage()); e.printStackTrace(); } } public void itemStateChanged(ItemEvent e){ repaint(); } } //sulgeb akna X-ist class Raamikuular extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.out.println("Sulgen akna!"); System.exit(0); } }