Archived

This topic is now archived and is closed to further replies.

StrikerNR

(java) trouble drawing lines in JInternalFrames

Recommended Posts

I have been having trouble drawing lines in the internal frames i have in my application. I basically invoke the g.drawLine() method in the paint function. But the line doesn''t show up when i run the app. I would appreciate if could tell me where i am going wrong. Below i posted the relevant parts of my code to look at. Thanks
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.event.*;
import javax.swing.filechooser.*;


public class Morph extends JFrame implements ActionListener {
	
	
	JDesktopPane desktop;
	JFileChooser fileChooser;
	JInternalFrame s;
	JInternalFrame d;
	SWindow sw;DWindow dw;
	
	public static void main(String [] args){
		Morph a=new Morph("Morph");
		a.setSize(500,500);
		a.setVisible(true);
	}
	
	public Morph(String title){
		super(title);
	  	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	  	//setJMenuBar(createMenuBar());
	  	
	  	Container content = getContentPane();
		desktop = new JDesktopPane();
    		
    	content.add(desktop, BorderLayout.CENTER);
	  	
	  	sw=new SWindow();dw=new DWindow();
	  	
	  	fileChooser = new JFileChooser();
	}
	
	
	
	
	
	public void actionPerformed(ActionEvent e) {}
	
	
	
	
	
	public class SWindow implements MouseListener{
		
		ImagePanel imagePanel;
		public SWindow(){
			init();
			
			
		}
		
		protected void init(){
			s=new JInternalFrame("Source",true, true, false);
			setDefaultCloseOperation(JInternalFrame.EXIT_ON_CLOSE);
			
			s.addMouseListener(this);
			
			imagePanel=new ImagePanel();
	    	s.getContentPane().add(imagePanel, BorderLayout.CENTER);
		
			
		
			s.setLocation(0, 20);
      		s.setSize(200, 200);
      	
      		desktop.add(s);
      		
      		
			pack();
			s.setVisible(true);
		}
		
		public boolean setImage(String fileName){
			return imagePanel.setImage("images/"+fileName);
		}
			
			
		public void paint(Graphics g){
			g.setColor(Color.black);
			g.drawLine(0,0,100,200);
			s.repaint();
		}
		
	
		public void mouseClicked(MouseEvent e){
			
			System.out.println("sadas");
			
			
		}
          
 		public void mouseEntered(MouseEvent e){}
          
 		public void mouseExited(MouseEvent e){}
          
 		public void mousePressed(MouseEvent e){}
          
 		public void mouseReleased(MouseEvent e) {}
		
	}
	
	
	
	
	
	
	
	public class DWindow implements MouseListener{
		
		ImagePanel imagePanel;
		public DWindow(){
			init();
			Graphics g= getGraphics();
			System.out.println(g);
			
			
		}
		
		protected void init(){
			d=new JInternalFrame("Destination",true, true, false);
			setDefaultCloseOperation(JInternalFrame.EXIT_ON_CLOSE);
			
			d.addMouseListener(this);
			
			imagePanel=new ImagePanel();
	    	d.getContentPane().add(imagePanel, BorderLayout.CENTER);
		
			
		
			d.setLocation(200, 20);
      		d.setSize(200, 200);
      	
      		desktop.add(d);
      		
      		
			pack();
			d.setVisible(true);
		}
		
		public boolean setImage(String fileName){
			return imagePanel.setImage("images/"+fileName);
		}
			
			
		public void paint(Graphics g){
			g.setColor(Color.black);
			g.drawLine(0,0,100,200);
			d.repaint();
		}
		
		public void mouseClicked(MouseEvent e){
			
			System.out.println("sadas");
			
			
		}
          
 		public void mouseEntered(MouseEvent e){}
          
 		public void mouseExited(MouseEvent e){}
          
 		public void mousePressed(MouseEvent e){}
          
 		public void mouseReleased(MouseEvent e) {}
 		
 		
		
	}
	
}
 
-------------------------------------------------------------------------------------------------------------------------- F22 Lightning 3 Screen Saver: F22L3ScreenSaver.exe

Share this post


Link to post
Share on other sites