Results 1 to 14 of 14
  1. #1
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default FAO Fubarable...Or anybody with Swing Expierience

    Not even that much Swing expierience I would say... but anyway read below.

    If your College teacher insisted on drawing to a JFrame and insisted that the point 0,0 was hidden because of a java bug and resizing the same, and that flickering was a fault even though JPanel comes with her doubleBuffered method, would you except that? not as a student but as a programmer? please be truthful thanks, Fubarable.

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    I better be right or I am going to fail maths D

  3. #3
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Guys you exempt from crticism I did it for my mates in college to maker them see wot a professor can get wrong and that woz alll.

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Yup a pair of balls is foreign to the programmers and math people tooo, 100% or 0 % what diff do it make only they cant program, but u obviously cannot.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  6. #6
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Fubarable just my first post? what do you think?

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by al_Marshy_1981 View Post
    Fubarable just my first post? what do you think?
    We've all had professors who have made mistakes. This is not a problem as long as he/she are open to suggestions for improvement (though done in private to allow him to save face).

  8. #8
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Fubarable in your opinion if your were going to teach mathematic graphics can I reasonably say you would know to draw onto a JPanel and not JFrame? i am not even that a great graphics programmer but I know not to say java bugs coz a teacher thinks drawing to JFrame is the same as drawing to JPanel, please back me up fubarable!!!

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Of course you're right and he's wrong. But have you discussed this with him? The best way to demonstrate your point is to create two small programs, one with animation that draws on a JFrame and the other with animation that draws on a JPanel and allow him to see the difference double buffering makes.

  10. #10
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    thanks fubarable that is a good suggestion in fact i could have the figure turn and show him double buffered in a JPanel and the extra code involved in a JFrame.

    You know what really does me head in Fubarable he is convinced it is a bug that Jrame considereds it a bug a JFrame cannot be resized and that aJPanel has ( a human cooordinate for 0,0) that just drives me mad as you can imagine,He cannot or listen to beyond a JFame nd i aint even that expeirenced but I know to listen to you all who give advice.... buh I dont belive in java ias at fault, that is a lie, and everybody who has studied knows jpanel can rectify what he calls bugs. do you agree?

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  12. #12
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    thanks Fubarable for your time as usual...

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Something like....

    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class DrawingInFrameAndPanel {
       private static final Dimension GUI_SIZE = new Dimension(1000, 100);
       private static final int TIMER_DELAY = 10;
       private static final Font FONT = new Font(Font.SANS_SERIF, Font.BOLD, 32);
       private static final int DELTA_X = 1;
    
       private static void createAndShowUI() {
          String frameString = "Drawing in JFrame";
          MyFrame drawInFrameFrame = new MyFrame(frameString, frameString, DELTA_X);
          drawInFrameFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          drawInFrameFrame.getContentPane().setPreferredSize(GUI_SIZE);
          drawInFrameFrame.setFont(FONT);
          drawInFrameFrame.pack();
          drawInFrameFrame.setLocationRelativeTo(null);
          Point location = drawInFrameFrame.getLocation();
          drawInFrameFrame.setLocation(location.x, location.y - 100);
          drawInFrameFrame.setVisible(true);
          
          String panelString = "Drawing in JPanel";
          MyPanel myPanel = new MyPanel(panelString , DELTA_X);
          myPanel.setPreferredSize(GUI_SIZE);
          myPanel.setFont(FONT);
          
          JFrame drawInPanelFrame = new JFrame("Drawing In Panel");
          drawInPanelFrame.getContentPane().add(myPanel);
          drawInPanelFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          drawInPanelFrame.pack();
          drawInPanelFrame.setLocationRelativeTo(null);
          location = drawInPanelFrame.getLocation();
          drawInPanelFrame.setLocation(location.x, location.y + 100);
          drawInPanelFrame.setVisible(true);
          
          final Movable[] movables = {drawInFrameFrame, myPanel};
          new Timer(TIMER_DELAY, new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                for (Movable movable : movables) {
                   movable.move();
                }
             }
          }).start();
       }
    
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }
    
    interface Movable {
       public void move();
    }
    
    @SuppressWarnings("serial")
    class MyFrame extends JFrame implements Movable {
       private String text;
       private int textX = 10;
       private int textY = 53;
       private int deltaX;
       
       public MyFrame(String title, String text, int deltaX) {
          super(title);
          this.text = text;
          this.deltaX = deltaX;
          getContentPane().setLayout(new FlowLayout());
          getContentPane().add(new JButton("Button"));
       }
       
       public void move() {
          int width = getWidth();
          if (textX >= width) {
             deltaX = -Math.abs(deltaX);
          }
          if (textX <= 0) {
             deltaX = Math.abs(deltaX);
          }
          textX += deltaX;
          repaint();
       }
       
       @Override
       public void paint(Graphics g) {
          super.paint(g);
          g.drawString(text, textX, textY);
       }
    }
    
    @SuppressWarnings("serial")
    class MyPanel extends JPanel implements Movable {
       private String text;
       private int textX = 10;
       private int textY = 25;
       private int deltaX;
       
       public MyPanel(String text, int deltaX) {
          this.text = text;
          this.deltaX = deltaX;
          add(new JButton("Button"));
       }
       
       public void move() {
          int width = getWidth();
          if (textX >= width) {
             deltaX = -Math.abs(deltaX);
          }
          if (textX <= 0) {
             deltaX = Math.abs(deltaX);
          }
          textX += deltaX;
          repaint();
       }
       
       @Override
       public void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.drawString(text, textX, textY);
       }
    }

  14. #14
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Seriously Fubarable, I agree with you but it just was not acceptable to this person and as far as I am concerned, his marks confirmed it, he had a lot of math knowledge but zero java knowledge. but thought he did drawing on JFrames etc which just made me go insane all semester, but I take the blame because I tried to accomodate him instead of showing him the proper way to do it. and i want every student to know after this to never be afraid of your tutor if you know in your heart and programming they are wrong. maybe I was too nice....

Similar Threads

  1. swing.jar
    By krrishnak in forum AWT / Swing
    Replies: 2
    Last Post: 04-05-2009, 06:29 AM
  2. MVC and swing
    By jurka in forum AWT / Swing
    Replies: 1
    Last Post: 09-15-2008, 02:32 PM
  3. AWT or Swing
    By bugger in forum AWT / Swing
    Replies: 4
    Last Post: 11-22-2007, 10:44 AM
  4. where is the swing jar?
    By katie in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 11:58 PM
  5. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 08:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •