<br>Hi all, I am implementing a GUI interface using swing. One of the requirements is to call JPanel in a loop.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Smita_Thakur
Posted On:   Monday, August 6, 2001 04:52 AM

The way i am doing is, i have a class called Rxnfile.java, which is calling Molfile2.java in a loop....which in turn is calling class Molfile_Drawarea.java which is a JPanel. Now my program should be able to place the output of the Molfile2.java which will be a structure at differeft positions in the JFrame....., in other words each time JPanel is called ,it should be attached in the JFrame at different positions.....so that instead of showing only the last structure...it should show all the structures ,required in a line. import java.io.*; import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Rxnfile extends JFrame{    More>>

The way i am doing is, i have a class called Rxnfile.java, which is calling Molfile2.java in a loop....which in turn is calling class Molfile_Drawarea.java which is a JPanel. Now my program should be able to place the output of the Molfile2.java which will be a structure at differeft positions in the JFrame....., in other words each time JPanel is called ,it should be attached in the JFrame at different positions.....so that instead of showing only the last structure...it should show all the structures ,required in a line.



			
				
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Rxnfile extends JFrame{

private JPanel molfilePanel;

public Rxnfile()
{
super("A viewer for chemical structure");

Molfile2 molfile = new Molfile2();
molfilePanel = new JPanel();
try{
File filename = new File( "oxygen_mol.txt");
FileReader file = new FileReader(filename);
BufferedReader buff = new BufferedReader(file);

.
.
.
.
.
.
.
int ppp = rrrppp.getNum_product();
molfilePanel.setLayout(new GridLayout(1,(rrr+ppp),5,5));

for(int i=0;i <(rrr+ppp);i++)
{
line = buff.readLine();
System.out.println(line);

if(line.equals("$MOL"))
{
molfile.setBuffReader( buff );
molfile.doWork();
molfile.repaint();
molfilePanel.add(molfile);
}//end of if loop

}//end of for loop
//}//end of while

buff.close();
Container c = getContentPane();
c.add(molfilePanel);
setSize(500,500);
show();

}catch (IOException e){
System.out.println("Error -- " + e.toString());}

}

public static void main(String args[] )
{
Rxnfile rxn = new Rxnfile();
rxn.addWindowListener
(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
}




			
				

import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Molfile2 extends JPanel{


...
private Molfile_drawarea drawarea = new Molfile_drawarea();
.........
private File filename;
private BufferedReader buffReader;


public void setFilename( File f )
{
filename = f;
}

public void setBuffReader( BufferedReader b )
{
buffReader = b;
}


public Molfile2()
{
}

public void doWork()
{
......
FileReader file;
........
//calls the method
headerline.header_block(buffReader);

//calls the method
countline.counts_line(buffReader);
.....
drawarea.draw(atom_symbol2, charge2,isotope2,x2,y2);

.......
..........
}//end of constructor


public void paintComponent( Graphics g )
{
super.paintComponent( g );
drawarea.paintComponent( g );
}

}//end of class





			
				
public class Molfile_drawarea extends JPanel {
.
..
..
public void paintComponent(Graphics g)
{
super.paintComponent( g );
.
.
.
.
}
}
   <<Less

Re: <br>Hi all, I am implementing a GUI interface using swing. One of the requirements is to call JPanel in a loop.

Posted By:   yoganandam_manchikanti  
Posted On:   Friday, August 10, 2001 02:53 AM

hi, no problem we can do it. is is just like a control array.
declare panel variable in global. and
assgin like
JPanel pnl = Structure;(stucture sholud be instance of panel)
pnl.setBounds(x,y,width,heitht);
Jframe.add(pnl);
If you want the panel instance through your program while adding put them in a HashMap with key value pairs.
About | Sitemap | Contact