24 Replies - 270 Views - Last Post: 28 January 2013 - 11:57 AM
#1
Changing content on Applet
Posted 26 January 2013 - 04:53 AM
Replies To: Changing content on Applet
#2
Re: Changing content on Applet
Posted 26 January 2013 - 05:00 AM
When the freeze occurs, are you getting an error message? If so, please include the error message, copied and pasted.
#3
Re: Changing content on Applet
Posted 26 January 2013 - 05:45 AM
#4
Re: Changing content on Applet
Posted 26 January 2013 - 05:59 AM
GregBrannon, on 26 January 2013 - 05:00 AM, said:
When the freeze occurs, are you getting an error message? If so, please include the error message, copied and pasted.
package kurybinis;
import java.sql.*;
import java.sql.DriverManager;
import javax.swing.*;
/*
* Programos paleidimo klase. Paleidžia programą.
*/
public class Pagrindine extends JApplet{
/*
* Kintamuju aprašymas
*/
private PrisijungimoLangas pl;
private Connection con;
/*
* Pagrindinis metodas. Sukuria klases "Pagrindine" objektą
*/
public static void main(String[] args){
Pagrindine pgr = new Pagrindine();
pgr.init();
}
/*
* JApplet paleidimo metodas.
*/
public void init(){
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
prisijungtiPrieBazes();
start();
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
e.printStackTrace();
}
}
/*
* Prisijungia prie duomenu bazes
*/
public void prisijungtiPrieBazes(){
try{
String drive = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(drive);
String db = "jdbc:odbc:kurybinis";
con = DriverManager.getConnection(db);
System.out.println("Prisijungta");
}catch(Exception e){}
}
/*
* Sukuria GUI objektą, grafiką.
*/
public void start(){
pl = new PrisijungimoLangas(con,this);
setContentPane(pl);
setSize(600,600);
}
}
Main class. And here is the first screen:
package kurybinis;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.sql.*;
public class PrisijungimoLangas extends JPanel implements ActionListener{
/*
* Kintamuju aprašymas
*/
private JPanel vidus;
private JTextField vartotojoVardas;
private JTextField slaptazodis;
private JButton prisijungti;
private JLabel pavadinimas;
private Connection con;
private Statement ps;
private ResultSet rt;
private String vardas;
private String slaptaz;
private Pagrindine pagr;
/*
* Konstruktorius. Gauna prisijungimo i duomenu baze kintamaji.
*/
public PrisijungimoLangas(Connection con, Pagrindine pagr){
this.con = con;
this.pagr = pagr;
nustatytiElementus();
}
/*
* Sukuria lango aplinką.
*/
public void nustatytiElementus(){
pavadinimas = new JLabel("PRISIJUNGIMAS");
pavadinimas.setFont(new Font("Serif",Font.BOLD,20));
vidus = new JPanel();
vidus.add(Box.createRigidArea(new Dimension(10, 170)));
vidus.add(pavadinimas);
vartotojoVardas = new JTextField("Prisijungimo vardas",20);
slaptazodis = new JPasswordField("slaptazodis",20);
prisijungti = new JButton("Prisijungti");
prisijungti.addActionListener(this);
vidus.setLayout(new BoxLayout(vidus,BoxLayout.Y_AXIS));
vidus.add(Box.createRigidArea(new Dimension(10, 30)));
vidus.add(vartotojoVardas);
vidus.add(Box.createRigidArea(new Dimension(10, 20)));
vidus.add(slaptazodis);
vidus.add(Box.createRigidArea(new Dimension(10, 30)));
vidus.add(prisijungti);
this.add(vidus);
}
/*
* Metodas paleidžiamas vartotojui užpildžius formą.
*/
@Override
public void actionPerformed(ActionEvent ae) {
try {
vardas = vartotojoVardas.getText().trim();
slaptaz = slaptazodis.getText().trim();
String sql = "select Username,Password from Table1 where Username = '"+vardas+"'and Password = '"+slaptaz+"'";
String sql2 = "select Already,Score from Table1 where Username = '"+vardas+"'and Password = '"+slaptaz+"'";
String sql3 = "select Score from Table1 where Username = '"+vardas+"'and Password = '"+slaptaz+"'";
ps = con.createStatement();
rt = ps.executeQuery(sql);
int count = 0;
while(rt.next()){
count++;
}
ps.close();
if(count == 1){
ps = con.createStatement();
ps = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
rt = ps.executeQuery(sql2);
while(rt.next()){
int points = rt.getInt("Score");
rt.updateString("Already","Yes");
rt.updateInt("Score", points+7);
rt.updateRow();
}
ps.close();
System.out.println("OK");
pagr.setContentPane(new Instrukcijos(con,pagr));
}
else if(count == 0)
JOptionPane.showMessageDialog(this, "Tokio vartotojo nera. Bandykite dar kartą");
}catch(Exception e){
e.printStackTrace();
}
}
}
Here is simple instructions screen:
package kurybinis;
import javax.swing.*;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.*;
import java.sql.*;
public class Instrukcijos extends JPanel implements ActionListener{
private Connection con;
private Pagrindine pagr;
private JLabel pavadinimas;
private JPanel vidus;
public Instrukcijos ( Connection con, Pagrindine pagr ){
this.con = con;
this.pagr = pagr;
rasytiInstrukcijas();
}
private void rasytiInstrukcijas() {
pavadinimas = new JLabel("INSTRUKCIJOS");
pavadinimas.setFont(new Font("Serif",Font.BOLD,20));
vidus = new JPanel();
vidus.add(Box.createRigidArea(new Dimension(10, 70)));
vidus.add(pavadinimas);
this.add(vidus);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
I don't get any error messages. It simply freezes, and for example if I pop up another window (browser or any other) and then open again my program window it becomes blank white.
#5
Re: Changing content on Applet
Posted 26 January 2013 - 09:02 AM
#6
Re: Changing content on Applet
Posted 26 January 2013 - 09:25 AM
a. the applet will need to be signed to do that
b. the database needs to be on the same machine as the browser you're viewing it in. In which case - why not use an application?
This post has been edited by g00se: 26 January 2013 - 09:29 AM
#7
Re: Changing content on Applet
Posted 26 January 2013 - 09:32 AM
g00se, on 26 January 2013 - 09:25 AM, said:
a. the applet will need to be signed to do that
b. the database needs to be on the same machine as the browser you're viewing it in. In which case - why not use an application?
How can I add application in the browser? DO I need to use Java Web Start?
My programming knowledge is still poor, so don't judge me if I make so many mistakes.
This post has been edited by novakasss: 26 January 2013 - 10:12 AM
#8
Re: Changing content on Applet
Posted 26 January 2013 - 10:36 AM
Quote
Well that wouldn't be much different to using an applet. Questions for you?
a. where is the db - on the browser machine or a server somewhere?
b. why do you want a web browser have to be involved at all?
#9
Re: Changing content on Applet
Posted 26 January 2013 - 10:37 AM
g00se, on 26 January 2013 - 10:36 AM, said:
Quote
Well that wouldn't be much different to using an applet. Questions for you?
a. where is the db - on the browser machine or a server somewhere?
b. why do you want a web browser have to be involved at all?
At this time db is in my computer. I created it with Microsoft Access. But I will create another MySQL on web host.
I want to involve web browser, because I will add this program in to my website.
This post has been edited by novakasss: 26 January 2013 - 10:38 AM
#10
Re: Changing content on Applet
Posted 26 January 2013 - 10:37 AM
Per this thread.
#11
Re: Changing content on Applet
Posted 26 January 2013 - 10:42 AM
Quote
That's a completely different issue and a much better scenario. Host the applet on the same machine as the MySql db - problem solved. The applet is a front end to your db and doesn't even need to be signed.
The only small problem is that a client-side db connection is not quite as secure, but if you enforce login, it's not too bad, though theoretically credentials might be sniffable
#12
Re: Changing content on Applet
Posted 26 January 2013 - 10:47 AM
g00se, on 26 January 2013 - 10:42 AM, said:
Quote
That's a completely different issue and a much better scenario. Host the applet on the same machine as the MySql db - problem solved. The applet is a front end to your db and doesn't even need to be signed.
The only small problem is that a client-side db connection is not quite as secure, but if you enforce login, it's not too bad, though theoretically credentials might be sniffable
I wanted first to create a program inside my pc. And I don't understand this sentence:
The applet is a front end to your db and doesn't even need to be signed.
sign applet. What is that mean?
#13
Re: Changing content on Applet
Posted 26 January 2013 - 10:50 AM
#14
Re: Changing content on Applet
Posted 26 January 2013 - 01:02 PM
java.sql.SQLException: Access denied for user 'sportovikt_base'@'78.61.73.165' (using password: YES)
Is that mean that I correctly connected to database, and only password I need?
I'm asking because I'm using this form:
on = DriverManager.getConnection(url,userName,password);
And I think I filled in information correctly.
And here is the url:
String url = "jdbc:mysql://sportoviktorina.lt/phpmyadmin/sportovikt_db";
Is this a good form? Do I need to write my website address after that mysql?
#15
Re: Changing content on Applet
Posted 26 January 2013 - 01:07 PM
|
|

New Topic/Question
Reply



MultiQuote






|