The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

cant understand why?

Posted by arun on July 21, 2001 at 3:23 AM

hi,

have just started learning Java. I wanna add a panel and the canvas in a JFrame(swing) , but i cant.
However, i can either see panel or canvas, not both in a frame.

here is my code.
can anybody help me plz?

Arun


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

public class Amplifier extends JPanel{
JPanel mainPane;

public Amplifier(){
mainPane = new JPanel();
Graph graph = new Graph();
Converter fred = new Converter();
mainPane.setLayout(new BorderLayout());
mainPane.add(new Label("Amplifier", Label.CENTER), BorderLayout.NORTH);
mainPane.add(fred, BorderLayout.WEST);
mainPane.add(graph, BorderLayout.CENTER);
}

public static void main(String[] args){

Amplifier amplifier = new Amplifier();
Converter fred = new Converter();
JFrame f = new JFrame("Project");
f. addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});

f.setContentPane(amplifier.mainPane);
f.setContentPane(fred.mainPane);
f.pack();
f.setVisible(true);
}
}



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us