Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Applets
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Applets
Applet blinking, DB doesn't work
Raphael Euclydes
Greenhorn
Posts: 3
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi guys,
I have an
applet
that refreshes every second, but it keeps flashing on repaint. I tried to apply the Double Buffer on it but it keeps blinking. Did I use the DB right? Is something missing? Thanks a lot.
import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; import javax.swing.JApplet; import javax.swing.Timer; public class TempoReal extends JApplet implements ActionListener { private static final long serialVersionUID = 1L; Image campo; // The object we will use to write with instead of the standard screen graphics Graphics bufferGraphics; public void init() { setBackground(new Color(0,130,0)); campo = createImage(600,400); bufferGraphics = campo.getGraphics(); } public TempoReal() { super(); setSize(600,400); setVisible(true); final Timer timer = new Timer(1000, this); timer.start(); } public void actionPerformed(final ActionEvent e) { repaint(); } public void paint(final Graphics g) { Connection connection = null; Statement statement = null; super.paint(g); int comprimento = 0; int largura = 0; int col = 0; int linha = 0; int row = largura; String sessao=""; final int ambiente = Integer.parseInt(getParameter("ambiente")); try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException cnfe) { System.out.println("Error loading driver: " + cnfe); } Properties userInfo = new Properties(); userInfo.put("user", "postgres"); userInfo.put("password", "postgres"); try { connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", userInfo); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try {statement = connection.createStatement();} catch (SQLException e) {e.printStackTrace();} String query = "SELECT MAX(\"SESS_SEQUENCIAL\") FROM \"SISTRACK_SESSAO\""; ResultSet result = null; try {result = statement.executeQuery(query);} catch (SQLException e) {e.printStackTrace();} try { result.next(); sessao = result.getString(1); } catch (SQLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } query = "SELECT \"AMBI_LARGURA_M\",\"AMBI_COMPRIMENTO_M\" FROM \"SISTRACK_AMBIENTE\" WHERE \"AMBI_ID\"="+ambiente; try { result = statement.executeQuery(query); result.next(); largura = result.getInt(1); comprimento = result.getInt(2); } catch (SQLException e) {e.printStackTrace();} bufferGraphics.clearRect(0,0,600,400); //Pinta campo de verde bufferGraphics.setColor(new Color(0,130,0)); bufferGraphics.fillRect(0, 0, comprimento*5+20, largura*5+30); //bufferGraphics.setStroke(new BasicStroke(1.5f)); //Desenha as linhas bufferGraphics.setColor(new Color(255,255,255)); //Desenha as laterais bufferGraphics.drawRect(17, 17, (comprimento-3)*5, (largura-1)*5); //Desenha o meio campo bufferGraphics.drawLine((comprimento/2)*5-5,largura*5+10,(comprimento/2)*5-5,17); //Desenha as grandes áreas bufferGraphics.drawRect(17, ((largura-35)*5)/2, 17*5, 41*5); bufferGraphics.drawRect((comprimento-17)*5+2, ((largura-35)*5)/2, 17*5, 41*5); //Desenha as pequenas áreas bufferGraphics.drawRect(17, ((largura-12)*5)/2, 6*5, 18*5); bufferGraphics.drawRect((comprimento-6)*5+2, ((largura-12)*5)/2, 6*5, 18*5); //Desenha marca do penalti bufferGraphics.fillOval(17+(11*5), (largura*5)/2+13, 3, 3); bufferGraphics.fillOval(comprimento*5-(11*5), (largura*5)/2+13, 3, 3); //Desenha os semicírculos //bufferGraphics.setStroke(new BasicStroke(2.0f)); bufferGraphics.drawArc(85, ((largura-40)*5)/2+79, 39, 70, 270, 180); bufferGraphics.drawArc((comprimento-17)*5-20, ((largura-39)*5)/2+79, 40, 70, 90, 180); //Desenha o círculo central bufferGraphics.drawOval((comprimento*5)/2-50, (largura*5)/2-30, 90, 90); bufferGraphics.drawOval((comprimento*5)/2-6, (largura*5)/2+15, 3, 3); //Desenha corners bufferGraphics.drawArc(14, 14, 10, 10, 0, -90); bufferGraphics.drawArc(14, largura*5+5, 10, 10, 0, 90); bufferGraphics.drawArc(comprimento*5-5, 14, 10, 10, 180, 90); bufferGraphics.drawArc(comprimento*5-5, largura*5+5, 10, 10, 180, -90); query = "SELECT \"TAG_NUMERO_CAMISA\", \"LOCA_COORDE_X\", \"LOCA_COORDE_Y\""+ "FROM \"SISTRACK_LOCALIZACAO\" LOCA1, \"SISTRACK_TAG\""+ "WHERE \"LOCA_TIMESTAMP\" = (SELECT MAX(\"LOCA_TIMESTAMP\") "+ "FROM \"SISTRACK_LOCALIZACAO\" LOCA2 "+ "WHERE LOCA2.\"LOCA_TAG_ID\" = LOCA1.\"LOCA_TAG_ID\")"+ "AND \"LOCA_TAG_ID\" = \"TAG_ID\"" + "AND \"LOCA_TIMESTAMP\" BETWEEN (SELECT \"SESS_INICIO\" FROM \"SISTRACK_SESSAO\" WHERE \"SESS_SEQUENCIAL\"=1)"+ "AND (SELECT \"SESS_FIM\" FROM \"SISTRACK_SESSAO\" WHERE \"SESS_SEQUENCIAL\"=1)"+ "ORDER BY 2,3"; try {result = statement.executeQuery(query);} catch (SQLException e) {e.printStackTrace();} bufferGraphics.setColor(new Color(255,255,255)); bufferGraphics.setFont(new Font("Sans Serif",Font.BOLD,11)); try { while(result.next()){ bufferGraphics.setColor(new Color(255,255,255)); bufferGraphics.fillOval((result.getInt(2)-3)*5-3, (largura-result.getInt(3)-2)*5, 15, 15); bufferGraphics.setColor(new Color(0,0,0)); if(result.getInt(1)<10){ bufferGraphics.drawString(String.valueOf(result.getInt(1)), (result.getInt(2)-3)*5+2, (largura-result.getInt(3))*5+1); }else{ bufferGraphics.drawString(String.valueOf(result.getInt(1)), (result.getInt(2)-3)*5-2, (largura-result.getInt(3))*5+1); } } } catch (SQLException e) { e.printStackTrace(); } g.drawImage(campo,0,0,this); } public void update(Graphics g) { paint(g); } public static void main(final String[] args) { final TempoReal tr = new TempoReal(); } }
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
java.sql.SQLException: ORA-01858: a non-numeric character was found where a numeric
Break the loop using threads
Convert OutputStream to InputStream!
JDBC VRE 2.0 BatchUpdate
NULL pointer exception.
More...