Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 07-09-2004, 06:57 AM   #1 (permalink)
grfxer
Registered User
 
Join Date: Jul 2004
Posts: 1
grfxer is on a distinguished road
Swing And Database

Hello,
i have a database that stores a)machine name b)date c)condition in one table.Actually, it contains all machines and describes the condition each machine is according to date.
The date is like daymonthyear and thereare 8 conditions a machine can be in.

In my code,using swing i have created a slider that can choose daymonthyear.
I have also created the query that will print(it is System.out.println for now) the information.
What i want to do is
depict each condition a machine can be in with a colored circle(diffent color for all 8)
create an x-axis that will be the time
create a horizonatl line for each machine (the machines name will come from the result of the query)
create a vertical line for every date (the date will come from the result of the query)
where the horizontal line and the vertical meet a circle with a color will be drawn (showing in what condition
machine1 will be at time 12July20004 for example)
be able to use the slider on the x-axis to move to the requested date





My code is the following


package workingslider;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;

import java.sql.SQLException;
public class workingslider
extends JFrame {
public final static Dimension RIGID_DIMENSION =
new Dimension(1,3);
protected JLabel m_lbDate;
protected JSlider m_slYear;
protected JSlider m_slMonth;
protected JSlider m_slDay;
protected Hashtable m_labels;
protected GregorianCalendar m_calendar;
protected SimpleDateFormat m_dateFormat;
public workingslider() {
super("Date Slider");
setSize(500, 340);
m_calendar = new GregorianCalendar();
Date currDate = new Date();
m_calendar.setTime(currDate);
m_dateFormat = new SimpleDateFormat("EEE, MMM d, yyyyy");
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(4, 1));
JPanel p = new JPanel();
p.setBorder(new TitledBorder(new EtchedBorder(),"Selected Date"));
m_lbDate = new JLabel(
m_dateFormat.format(currDate) + " ");
m_lbDate.setFont(new Font("Arial",Font.BOLD,24));
p.add(m_lbDate);
p1.add(p);
m_slYear = new JSlider(JSlider.HORIZONTAL, 1990, 2010,
m_calendar.get(Calendar.YEAR));
m_slYear.setPaintLabels(true);
m_slYear.setMajorTickSpacing(5);
m_slYear.setMinorTickSpacing(1);
m_slYear.setPaintTicks(true);
ChangeListener lst = new ChangeListener() {
public void stateChanged(ChangeEvent e) {
showDate();
}
};
m_slYear.addChangeListener(lst);
p = new JPanel();
p.setBorder(new TitledBorder(new EtchedBorder(), "Year"));
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
p.add(Box.createRigidArea(RIGID_DIMENSION));
p.add(m_slYear);
p.add(Box.createRigidArea(RIGID_DIMENSION));
p1.add(p);
m_slMonth = new JSlider(JSlider.HORIZONTAL, 1, 12,
m_calendar.get(Calendar.MONTH)+1);
String[] months = (new DateFormatSymbols()).getShortMonths();
m_labels = new Hashtable(12);
for (int k=0; k<12; k++)
m_labels.put(new Integer(k+1), new JLabel(
months[k], JLabel.CENTER ));
m_slMonth.setLabelTable(m_labels);
m_slMonth.setPaintLabels(true);
m_slMonth.setMajorTickSpacing(1);
m_slMonth.setPaintTicks(true);
m_slMonth.addChangeListener(lst);
p = new JPanel();
p.setBorder(new TitledBorder(new EtchedBorder(), "Month"));
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
p.add(Box.createRigidArea(RIGID_DIMENSION));
p.add(m_slMonth);
p.add(Box.createRigidArea(RIGID_DIMENSION));
p1.add(p);
int maxDays = m_calendar.getActualMaximum(
Calendar.DAY_OF_MONTH);
m_slDay = new JSlider(JSlider.HORIZONTAL, 1, maxDays,
m_calendar.get(Calendar.DAY_OF_MONTH));
m_slDay.setPaintLabels(true);
m_slDay.setMajorTickSpacing(5);
m_slDay.setMinorTickSpacing(1);
m_slDay.setPaintTicks(true);
m_slDay.addChangeListener(lst);
p = new JPanel();
p.setBorder(new TitledBorder(new EtchedBorder(), "Day"));
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
p.add(Box.createRigidArea(RIGID_DIMENSION));
p.add(m_slDay);
p.add(Box.createRigidArea(RIGID_DIMENSION));
p1.add(p);
getContentPane().add(p1, BorderLayout.CENTER);
enableEvents(ComponentEvent.COMPONENT_RESIZED);
}
protected void processComponentEvent(ComponentEvent e) {
if (e.getID() == ComponentEvent.COMPONENT_RESIZED) {
int w = getSize().width;
m_slYear.setLabelTable(null);
if (w > 200)
m_slYear.setMajorTickSpacing(5);
else
m_slYear.setMajorTickSpacing(10);
m_slYear.setPaintLabels(w > 100);
m_slMonth.setLabelTable(w > 300 ? m_labels : null);
if (w <= 300 && w >=200)
m_slMonth.setMajorTickSpacing(1);
else
m_slMonth.setMajorTickSpacing(2);
m_slMonth.setPaintLabels(w > 100);
m_slDay.setLabelTable(null);
if (w > 200)
m_slDay.setMajorTickSpacing(5);
else
m_slDay.setMajorTickSpacing(10);
m_slDay.setPaintLabels(w > 100);
}
}
public void showDate() {
m_calendar.set(m_slYear.getValue(), m_slMonth.getValue()-1, 1);
int maxDays = m_calendar.getActualMaximum(
Calendar.DAY_OF_MONTH);
if (m_slDay.getMaximum() != maxDays) {
m_slDay.setValue(Math.min(m_slDay.getValue(), maxDays));
m_slDay.setMaximum(maxDays);
m_slDay.repaint();
}
m_calendar.set(m_slYear.getValue(), m_slMonth.getValue()-1,m_slDay.getValue());
Date date = m_calendar.getTime();
m_lbDate.setText(m_dateFormat.format(date));



}
public static void main(String argv[]) {
workingslider frame = new workingslider();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setVisible(true);
String data="jdbc:odbc:mis_back";
// System.out.println("working");
try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(connection);
Statement st = conn.createStatement();
ResultSet rec = st.executeQuery("SELECT machine,date,condition FROM base");

while(rec.next()){


String a =rec.getString("machine");
System.out.println(a+"");
String b =rec.getString("date");
System.out.println(b+"");
String c =rec.getString("condition");
System.out.println(c+"");



}
st.close();
}catch(Exception e){
System.out.println(e.toString());

}


}
}
grfxer is offline   Reply With Quote
Old 07-09-2004, 12:25 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,148
Belisarius is on a distinguished road
Sorry, I could help you with the DB stuff, but I'm no good with Swing.
__________________
GitS
Belisarius is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 10:53 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting