Problemer med applet
Den første metode i klassen Laesfradatabaser, skal udskrivefølgende data
"12345"+timevinkel+aekvatorvinkel+tilsyneladende+beskrivelse; til appletten, det skulle den gøre nede ved
Skriveflade.setText(laesfradatabaser.laes_massier());
i applet koden, men det jeg får er 12345nullnullnullnull
Nede ved public void test()i appletten køre det som det skal ved at skrive den rigtige info fra databasen db1.
Hvad er problemet?
import java.sql.*;
import java.util.*;
import java.io.*;
import java.net.*;
public class Laesfradatabaser
{
String timevinkel;
String aekvatorvinkel;
String tilsyneladende;
String beskrivelse;
public String laes_massier()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection massier = DriverManager.getConnection("jdbc:odbc:db1"); //db1 er datakildens navn, som findes
//under Kontrolpanel/Administrative Tools/
//Data Sources
Statement stmt = massier.createStatement();
ResultSet rs = stmt.executeQuery("SELECT timevinkel, aekvatorvinkel, tilsyneladende_storrelsesklasse, beskrivelse FROM Massier");
while (rs.next())
{
timevinkel = rs.getString("timevinkel");
aekvatorvinkel = rs.getString("aekvatorvinkel");
tilsyneladende = rs.getString("tilsyneladende_storrelsesklasse");
beskrivelse = rs.getString("beskrivelse");
// System.out.println(timevinkel+" "+aekvatorvinkel+" "+tilsyneladende);
}
}
catch(Exception f)
{
System.out.println("noget er galt "+f);
}
String info ="12345"+timevinkel+aekvatorvinkel+tilsyneladende+beskrivelse;
return info;
}
public String send_massier()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection massier = DriverManager.getConnection("jdbc:odbc:db1"); //db1 er datakildens navn, som findes
//under Kontrolpanel/Administrative Tools/
//Data Sources
Statement stmt = massier.createStatement();
ResultSet rs = stmt.executeQuery("SELECT timevinkel, aekvatorvinkel FROM Massier");
while (rs.next())
{
timevinkel = rs.getString("timevinkel");
aekvatorvinkel = rs.getString("aekvatorvinkel");
// System.out.println(timevinkel+""+aekvator+""+tilsyneladende+""+beskrive);
}
}
catch(Exception f)
{
System.out.println("noget er galt "+f);
}
String info = timevinkel+aekvatorvinkel;
return info;
}
}
//applet
import java.applet.Applet;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.text.*;
public class Teleskopstyring extends Applet implements ActionListener
{
Button Laesfradatabaser,Gemkordinater,Tid;
Choice cl;
Label Maerke,Maerke2,Maerke3,Maerke4;
TextField Skrivefelt,Skrivefelt2,Skrivefelt3,Skrivefelt4;
TextArea Skriveflade;
Laesfradatabaser laesfradatabaser = new Laesfradatabaser();
Tid tid = new Tid();
//******************************************************************************
public void init()
{
setLayout(new FlowLayout());
Gemkordinater = new Button("Gem kordinater");
Laesfradatabaser = new Button("Hent Massier info");
Tid = new Button("Hent Tid");
cl = new Choice();
Maerke = new Label(" Timevinkel øst vest eks :Sr 45:22:30#");
Maerke2 = new Label("Ækvatorvinkel nord syd eks Sd +23*15:00#");
Maerke3 = new Label(" Tilsyneladende størrelsesklasse");
Maerke4 = new Label(" beskrivelse");
Skrivefelt = new TextField(" ");
Skrivefelt2 = new TextField(" ");
Skrivefelt3 = new TextField(" ");
Skrivefelt4 = new TextField(" ");
Skriveflade = new TextArea();
cl.addItem("None");
cl.addItem("M1"); cl.addItem("M2"); cl.addItem("M3"); cl.addItem("M4");
cl.addItem("M5"); cl.addItem("M6"); cl.addItem("M7"); cl.addItem("M8");
cl.addItem("M9"); cl.addItem("M10"); cl.addItem("M11"); cl.addItem("M12");
cl.addItem("M13"); cl.addItem("M14"); cl.addItem("M15"); cl.addItem("M16");
cl.addItem("M17"); cl.addItem("M18"); cl.addItem("M19"); cl.addItem("M20");
cl.addItem("M21"); cl.addItem("M22"); cl.addItem("M23"); cl.addItem("M24");
cl.addItem("M25"); cl.addItem("M26"); cl.addItem("M27"); cl.addItem("M28");
cl.addItem("M29"); cl.addItem("M30"); cl.addItem("M31"); cl.addItem("M32");
cl.addItem("M34"); cl.addItem("M35"); cl.addItem("M36"); cl.addItem("M37");
cl.addItem("M38"); cl.addItem("M39"); cl.addItem("M40"); cl.addItem("M41");
cl.addItem("M42"); cl.addItem("M43"); cl.addItem("M44"); cl.addItem("M45");
cl.addItem("M46"); cl.addItem("M47"); cl.addItem("M48"); cl.addItem("M49");
cl.addItem("M50"); cl.addItem("M51"); cl.addItem("M52"); cl.addItem("M53");
cl.addItem("M54"); cl.addItem("M55"); cl.addItem("M56"); cl.addItem("M57");
cl.addItem("M58"); cl.addItem("M59"); cl.addItem("M60"); cl.addItem("M61");
cl.addItem("M62"); cl.addItem("M63"); cl.addItem("M64"); cl.addItem("M65");
cl.addItem("M66"); cl.addItem("M67"); cl.addItem("M68"); cl.addItem("M69");
cl.addItem("M70"); cl.addItem("M71"); cl.addItem("M72"); cl.addItem("M73");
cl.addItem("M74"); cl.addItem("M75"); cl.addItem("M76"); cl.addItem("M77");
cl.addItem("M78"); cl.addItem("M79"); cl.addItem("M80"); cl.addItem("M81");
cl.addItem("M82"); cl.addItem("M83"); cl.addItem("M84"); cl.addItem("M85");
cl.addItem("M86"); cl.addItem("M87"); cl.addItem("M88"); cl.addItem("M89");
cl.addItem("M90"); cl.addItem("M91"); cl.addItem("M92"); cl.addItem("M93");
cl.addItem("M94"); cl.addItem("M95"); cl.addItem("M96"); cl.addItem("M97");
cl.addItem("M98"); cl.addItem("M99"); cl.addItem("M100"); cl.addItem("M101");
cl.addItem("M102"); cl.addItem("M103"); cl.addItem("M104"); cl.addItem("M105");
cl.addItem("M106"); cl.addItem("M107"); cl.addItem("M108"); cl.addItem("M109");
cl.addItem("M110");
add(cl); //Rækkefølgen af add(); bestemmer hvordan
add(Maerke); //den grafiske brugerflade skal se ud
add(Skrivefelt);
add(Maerke2);
add(Skrivefelt2);
add(Maerke3);
add(Skrivefelt3);
add(Maerke4);
add(Skrivefelt4);
add(Gemkordinater);
add(Laesfradatabaser);
add(Tid);
add(Skriveflade);
Laesfradatabaser.addActionListener(this);
Tid.addActionListener(this);
}
//*************************************************************************************
public void test()
{
System.out.println(laesfradatabaser.laes_massier());
System.out.println("Tjek");
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == Laesfradatabaser)
{
Skriveflade.setText(laesfradatabaser.laes_massier());
}
if (e.getSource() == Tid)
{
Skriveflade.setText(tid.tider());
}}}