Click here to Skip to main content
15,888,521 members
Home / Discussions / Java
   

Java

 
GeneralRe: Code to convert from C# to Java (with goto) Pin
Kujtim Hyseni9-Jan-14 1:45
Kujtim Hyseni9-Jan-14 1:45 
GeneralRe: Code to convert from C# to Java (with goto) Pin
Richard MacCutchan9-Jan-14 1:52
mveRichard MacCutchan9-Jan-14 1:52 
QuestionTool for generating JNI (calling C/C++ code from java) Pin
doofx8-Jan-14 3:19
doofx8-Jan-14 3:19 
AnswerRe: Tool for generating JNI (calling C/C++ code from java) Pin
Richard MacCutchan8-Jan-14 6:09
mveRichard MacCutchan8-Jan-14 6:09 
GeneralRe: Tool for generating JNI (calling C/C++ code from java) Pin
doofx8-Jan-14 6:25
doofx8-Jan-14 6:25 
GeneralRe: Tool for generating JNI (calling C/C++ code from java) Pin
Richard MacCutchan8-Jan-14 6:44
mveRichard MacCutchan8-Jan-14 6:44 
GeneralRe: Tool for generating JNI (calling C/C++ code from java) Pin
doofx8-Jan-14 8:13
doofx8-Jan-14 8:13 
QuestionError in JFrame while Drawing Graphics2D Pin
f2630-Dec-13 19:54
f2630-Dec-13 19:54 
I have data in MySQL database i retrieve them to draw Graphics2D shapes, the data Stored in database as Medium-Text,
each 6 points(coordinates) in single line, i spilt spaces,new line and i parsed String[] to double[], i created 4 classes, -1st class for retrieving data from database.
-2nd class for pathEntry extends JPanel i declared 6 double variables to use them in paintComponent() method in curveTo() method(to draw curves).
-3rd class for Paths extends JPanel where i used ArrayList<pathentry> and called moveTo() method and loop on paintComponent() method in pathEntry class
-4th class i used JFrame to draw all Shapes are called from the last 3 classes to draw Shapes.
i stuck in the shapes did not display on the JFrame ?
1st Class:
Java
public class selectStmt {
public Paths db = null;
.....
 String values = null;
                        int noPrint = 0;
                            
                        while (rs.next()) {
                                values = rs.getString(1);
                                String[] valueNewLine = values.split("\\r\\n");
                                double[] Points = new double[valueNewLine.length];
                                
                                for(int i=0;i<valueNewLine.length;i++){
                                    Points = StringtoDoubleArray (valueNewLine [i]);
                                     db.add(valueNewLine[i]);
                                    //it's used for moveTo()
                                     //Points = new double[valueNewLine.length];
                                    db.MoveToX= Points [Points.length - 2];//the last point as X coordinate
                                    db.MoveToY = Points [Points.length - 1];//the last point as Y coordinate
                                            noPrint++;
                         if(noPrint % 6 == 0) {
                         System.out.println();//new line
                            noPrint = 0;
                        }}
...
 public double[] StringtoDoubleArray (String str){
         //System.out.println("StringtoDoubleArray " + str);
          double[] result = new double[6];
          String[] temp = str.split("\\s");
          
          for(int i=0;i<temp.length;i++){
            // System.out.println("StringtoDoubleArray i=" + i + "    temp=" +temp[i]); 
              result [i] = Double.parseDouble(temp[i]);
          }
          return result;
}

2nd Class:
Java
public class Paths extends JPanel{
  public double MoveToX=0;
    public double MoveToY=0;
    ArrayList <pathEntry> p=new ArrayList<pathEntry>();
           <a href="/Members/override">@Override</a>      
       public void paintComponent(Graphics g) {
            super.paintComponent(g);
            update(g);
       }
       public void update(Graphics g){
        
        Graphics2D g2d = (Graphics2D) g;
               GeneralPath path=new GeneralPath();
           path.moveTo(MoveToX,MoveToY);
         for ( int i = 0 ; i < p.size() ; i++ ) {
             p.get(i).paintComponent(g2d);
        }
		 //g2d.draw(path);  
	//g2d.fill(path);
       }
    public void paint_dump() {
        System.out.println(MoveToX+" "+MoveToY);
       for ( int i = 0 ; i < p.size() ; i++ ) {
           System.out.println(p.get(i));
        }
     }   
       
   public void add (String pathstr) {
       pathEntry pe=new pathEntry();                
       String[] temp = pathstr.split("\\s");
        pe.cx1 = Double.parseDouble(temp[0]);
        pe.cy1 = Double.parseDouble(temp[1]);
        pe.cx2 = Double.parseDouble(temp[2]);
        pe.cy2 = Double.parseDouble(temp[3]);
        pe.x2 = Double.parseDouble(temp[4]);
        pe.y2 = Double.parseDouble(temp[5]);
        this.p.add(pe);
     }
}

3rd Class:
Java
public class pathEntry  extends JPanel{
   public double cx1 = 0;
    public double cy1=0;
    public double cx2=0;
    public double cy2=0;
    public double x2=0;
    public double y2=0;
       <a href="/Members/override">@Override</a>               
       public void paintComponent(Graphics g) {
             super.paintComponent(g);
             update(g);
       }
        public void update(Graphics g){

		Graphics2D g2d = (Graphics2D) g;
         GeneralPath path=new GeneralPath();
		path.curveTo( cx1 , cy1 , cx2 , cy2 , x2 , y2 );
		g2d.draw(path);  
		g2d.fill(path);
   }
}

4th Class :
Java
public class Main extends JFrame  {
     public  selectStmt s;
    public static void main(String[] args){
             Main m=new Main();
    }
    public Main(){
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     setSize(1024, 768);
     setTitle("Drawing Shapes");
     setVisible(true);
     s = new selectStmt();
     add(s.db);
     s.db.paint_dump();
      }
    }


modified 31-Dec-13 5:38am.

AnswerRe: Error in JFrame while Drawing Graphics2D Pin
Richard MacCutchan30-Dec-13 23:06
mveRichard MacCutchan30-Dec-13 23:06 
GeneralRe: Error in JFrame while Drawing Graphics2D Pin
f2630-Dec-13 23:57
f2630-Dec-13 23:57 
Questionfinger prints (Bio Metrics) Pin
Member 1048716225-Dec-13 6:11
Member 1048716225-Dec-13 6:11 
AnswerRe: finger prints (Bio Metrics) Pin
jschell25-Dec-13 8:26
jschell25-Dec-13 8:26 
QuestionHow to access multiple webservices in single servlet Pin
revathi23423-Dec-13 20:26
revathi23423-Dec-13 20:26 
AnswerRe: How to access multiple webservices in single servlet Pin
jschell25-Dec-13 8:30
jschell25-Dec-13 8:30 
QuestionArrays in Web services Pin
V.22-Dec-13 23:26
professionalV.22-Dec-13 23:26 
AnswerRe: Arrays in Web services Pin
jschell25-Dec-13 8:38
jschell25-Dec-13 8:38 
GeneralRe: Arrays in Web services Pin
V.25-Dec-13 10:11
professionalV.25-Dec-13 10:11 
QuestionJava Tutorials Pin
tgsb22-Dec-13 22:50
tgsb22-Dec-13 22:50 
AnswerRe: Java Tutorials Pin
Richard MacCutchan22-Dec-13 23:23
mveRichard MacCutchan22-Dec-13 23:23 
GeneralRe: Java Tutorials Pin
techgeek from-india29-Dec-13 17:50
techgeek from-india29-Dec-13 17:50 
GeneralRe: Java Tutorials Pin
Richard MacCutchan29-Dec-13 22:46
mveRichard MacCutchan29-Dec-13 22:46 
Questionturing machine Pin
Member 1047236322-Dec-13 0:07
Member 1047236322-Dec-13 0:07 
QuestionSending Message from Java Application to Any Cell Phone Pin
Cyber1217-Dec-13 2:27
Cyber1217-Dec-13 2:27 
AnswerRe: Sending Message from Java Application to Any Cell Phone Pin
Richard MacCutchan17-Dec-13 2:48
mveRichard MacCutchan17-Dec-13 2:48 
AnswerRe: Sending Message from Java Application to Any Cell Phone Pin
ashish nimrot4-Jan-14 6:47
ashish nimrot4-Jan-14 6:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.