how to resize a canvas which has been added my applet Depends on the layout manager of its Container. Some layout managers like GridLayout and BorderLayout ignore some or all of the size information about the components you give them to layout. Other layout managers like FlowLayout and GridBagLayout respect the size requests of their child components. So how to work with this? Nesting components is one approach. The center section of a BorderLayout will expand its child component to fill itself in both horizontal and vertical dimensions (see BorderLayout api). So you can add the component to another component and add the second component to the BorderLayout. The intermediate component will expand to fill the center section of the BorderLayout and allow the component whose size you want to control to be displayed at its preferred size (which you may set). Another approach is to use a layout manager that will respect a components preferred size and call setPreferredSize on the component or, if the component is a class you can override getPreferredSize in the class and return a Dimension that reperesents the size you want for the component. See Lesson: Laying Out Components Within a Container.
is it possible to add a canvas to a JPanel Yes but it is recommended that we not mix AWT and Swing components. You can use a JPanel in Swing just like you use a Canvas in the AWT. If painting you use protected void paintComponent(Graphics g) instead of public void paint(Graphics g). See Implementing a Custom Component.