开发者

How to add Button in a Canvas?

I have a canvas and inside the canvas i have a webcam. On top of the video image, i want to place an "Button" and attach an event, so that i have control for full screen and minimize it. But this method is giving error, how to fix it?

  public static void main(String[] args) 
  { 

        JFrame frame = new JFrame("Overlay"); 
        frame.setBackground(Color.RED);

        // Canvas, to have a video and on top a button    
        final Canvas canvas = new Canvas(); 
        Button button = new Button(canvas); // ERROR
        button.setBounds(10,10, 100, 40);
        canvas.setPreferredSize(new Dimension(200, 200));     

        // Layout
        JPanel conte开发者_JAVA技巧nt = new JPanel(new GridLayout(2,2));
        content.add(canvas);
        content.add(new JButton("test"));  // for empty cell

        // Show
        frame.add(content);                        
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        frame.pack(); 
        frame.setVisible(true); 

        // Third party tools to capture the webcam, and plugin to our canvas
        final Video video = player.getElementByName("gl"); 
        XOverlay.wrap(video).setWindowID(canvas); 
    } 


It gives error because there are no constructor in Button class that takes canvas as an argument.You can add your button to same JPanel where you are adding your canvas.


canvas.add(button);

or

canvas.add(button, 55, 30);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜