import java.awt.*; import java.sql.*; import java.io.*; import java.applet.*; import java.awt.event.*; public class Graafik{ 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("nimi"); valik.add("aine"); 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:baas3", "", ""); Statement st=cn.createStatement(); //käib, loeb ab-s kokku, palju kirjeid on ja siis joonistab nende põhjal pildi if(valik.getSelectedItem().equals("nimi")){ p.setColor(Color.yellow); ResultSet nimi=st.executeQuery("SELECT count(*) as n FROM nimi"); nimi.next(); p.fillRect(125, 100, 50, nimi.getInt("n")*10); } if(valik.getSelectedItem().equals("aine")){ p.setColor(Color.blue); ResultSet aine=st.executeQuery("SELECT count(*) as a FROM aine"); aine.next(); p.fillRect(125, 100, 50, aine.getInt("a")*10); } } catch(Exception e) { System.out.println("Tekkis 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); } }