Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • gogata: holy crap time to make a rsps again 10 years later since i made this acc LOL
      Today at 03:23:51 PM
    • hodford: yo autoscape has keylogger in cache, ive been member in this community since 2011
      August 20, 2019, 08:57:42 PM
    • E S C O B A R: Anyone able to help me, i'm trying to find a decent source/client to start from , I haven't been near a laptop in over two years . Does much people still play RSPS's also?
      August 19, 2019, 04:52:38 PM
    • dan v jad: Great osrsps experience - check us out - join on discord! dxp, dpoints [link]
      August 19, 2019, 09:50:00 AM
    • ragnoroker: Brand new server! Double EXP is enabled right now aswell as other events! - [link]
      August 18, 2019, 07:14:43 AM
    • ragnoroker: Brand new server! Double EXP is enabled right now aswell as other events! - [link]
      August 18, 2019, 07:14:35 AM
    • puppajohn: Come and join us today for amazing content !
      August 16, 2019, 10:26:16 PM
    • puppajohn:[link] come and join us now! you have donator on your server? no problem we restore your donator credits and symbol ! free M box on loggins
      August 16, 2019, 10:26:02 PM
    • PavSwag: autoscape,0rg kill REVS for chance of TWISTED BOW || EP GETS YOU OSRS GP TOKENS
      August 15, 2019, 05:13:07 PM
    • hodford: autoscape,0rg is actually fudgein lit as come check it out
      August 13, 2019, 02:59:58 AM
    • ragnoroker: Brand new server! Hosting Raids Event all day + More! - 20+ online, Join today [link]
      August 11, 2019, 07:45:49 AM
    • ragnoroker: Brand new server! Hosting Raids Event all day + More! - 20+ online, Join today [link]
      August 11, 2019, 07:45:46 AM
    • PavSwag: autoscape,0rg kill REVS for chance of TWISTED BOW
      August 08, 2019, 07:29:43 PM
    • ragnoroker:Brand new server! Endless Content - Mature Players/Staff - 20+ online, Join today [link]
      August 08, 2019, 11:05:53 AM
    • ragnoroker:Brand new server! Endless Content - Mature Players/Staff - 20+ online, Join today [link]
      August 08, 2019, 11:05:46 AM
    • asshole_rule: bernie sanders
      August 06, 2019, 07:54:02 PM
    • PavSwag: #AS 100M OSRS GP GIVEAWAY!! [link] 317 Oldschool RuneScape Private Server emulating core factors of the game with a strong economy and balance of experience to bossing and prestiging -Receive DONATOR Perks by maxing to 99s- Lumbridge remade - Login with a starter set of armour and items - PK District - Preloading sets - Activity points for training - All Skills Working, Skilling Island, Skilling Pets, Skilling Rewards - All Working Max Capes - 25+ Bosses with Pets - Superior Slayer Encounters - Player Owned Shops - Minigames, Construction, Sawmill, Warriors Guild, Pest Control, Barrows (with pets), Fight Caves, Inferno Caves, Chambers of Xeric, Custom Raids - NPC Drop Table, Kills Tracker, Points Tracker, Extra settings. - Doubled Xp & Points Weekends - Vote System - Vote4Donor - Competitive Highscores - Tons of Content - Join us today for bonus giveaways and free ultra mystery box upon login!   Official YouTube Media: [youtube]P5D0eXEmjA4[/youtube] Join NOW Ill personally give you Ultra Mystery Boxes (Twisted Bow??) Im the Developer :smiley: Heres the Discord:  [link] BTW 100m OSRS GP Giveaways WEEKLY!
      August 05, 2019, 01:05:53 PM
    • ragnoroker: Brand new server! Endless Content - Mature Players/Staff - 20+ online, Join today :) - [link]
      August 05, 2019, 12:48:52 PM
    • ragnoroker: Brand new server! Endless Content - Mature Players/Staff - 20+ online, Join today :) - [link]
      August 05, 2019, 12:48:47 PM
    • suelo: does the search not work on here?
      August 05, 2019, 02:12:08 AM

    Author Topic: Graphics Java  (Read 1586 times)

    0 Members and 1 Guest are viewing this topic.

    OfflineRoar337

    • Member
    • ****
    • Posts: 252
    • Thanks: +0/-0
      • View Profile
    Graphics Java
    « on: August 05, 2016, 06:24:10 AM »
    So... I have always been undeniably terrible with the java swing paint type stuff here's what I'm trying to do:

    I need to use graphics to draw a image on screen and I also need to draw a line on string The line has to constantly be able to update and move but the image has no need to do this my issue is when i repaint It starts this annoying flickering and I cant figure out how to get rid of it I noticed that slowing down the painting stops the flickering but also makes the line laggy when it tries to move (Because they are painting together) Is there some way to repaint individual parts of graphics (Like instantiated graphics objects?)

    My goal is to basically render a cross hair over the mouse cursor and make it move with the cursor but it's also important that the image not flicker...

    I wonder if I made a tiny jpanel for the crosshair and updated its position with the render If that would work...
    « Last Edit: August 05, 2016, 06:25:46 AM by Roar337 »
    Code: [Select]
    for(int i=0; i < 2147483647; i++) {
    doFacedesk();
    }
    Runescape Gambling

    OfflineFat Cookies

    • Moparscape Vet
    • Global Moderator
    • *****
    • *
    • Posts: 3,834
    • Thanks: +0/-0
      • View Profile
    Re: Graphics Java
    « Reply #1 on: August 05, 2016, 08:13:55 AM »
    https://stackoverflow.com/questions/4274606/how-to-change-cursor-icon-in-java

    Don't use Java Swing, JavaFX is slightly better albeit with a steeper learning curve.




    Runescape Gambling

    Offlineobject

    • Member
    • ****
    • *
    • Posts: 440
    • Thanks: +0/-0
      • View Profile
    Re: Graphics Java
    « Reply #2 on: August 05, 2016, 11:28:37 AM »
    I'm not sure what you have right now. But maybe the following example can be of help?

    Code: Java
    1. importjava.awt.BorderLayout;
    2. importjava.awt.Color;
    3. importjava.awt.Graphics;
    4. importjava.awt.Graphics2D;
    5. importjava.awt.Point;
    6. importjava.awt.event.ActionEvent;
    7. importjava.awt.event.MouseEvent;
    8. importjava.awt.event.MouseMotionListener;
    9. importjava.awt.image.BufferedImage;
    10. importjava.io.IOException;
    11. importjava.net.URL;
    12.  
    13. importjavax.imageio.ImageIO;
    14. importjavax.swing.JFrame;
    15. importjavax.swing.JPanel;
    16. importjavax.swing.SwingUtilities;
    17. importjavax.swing.Timer;
    18.  
    19. publicfinalclass Test {
    20.         private Test(){
    21.                
    22.         }
    23.        
    24.         ////////////////////////////////////////////////////////////////////////////////////////////////////
    25.        
    26.         publicstaticvoid main(finalString[] args){
    27.                 SwingUtilities.invokeLater(Test::doRun);
    28.         }
    29.        
    30.         ////////////////////////////////////////////////////////////////////////////////////////////////////
    31.        
    32.         privatestaticvoid doRun(){
    33.                 final
    34.                 JFrame jFrame =newJFrame();
    35.                 jFrame.getContentPane().setLayout(newBorderLayout());
    36.                 jFrame.getContentPane().add(new JPanelImpl());
    37.                 jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    38.                 jFrame.setSize(1310, 256);
    39.                 jFrame.setLocationRelativeTo(null);
    40.                 jFrame.setTitle("HelloWorld in Java2D");
    41.                 jFrame.setVisible(true);
    42.                 jFrame.createBufferStrategy(2);
    43.         }
    44.        
    45.         ////////////////////////////////////////////////////////////////////////////////////////////////////
    46.        
    47.         privatestaticfinalclass JPanelImpl extendsJPanelimplementsMouseMotionListener{
    48.                 privatestaticfinallong serialVersionUID = 1L;
    49.                
    50.                 ////////////////////////////////////////////////////////////////////////////////////////////////////
    51.                
    52.                 privatefinalBufferedImage bufferedImage = doCreateBufferedImage();
    53.                 privatefinalPoint point =newPoint();
    54.                 privatefinalTimer timer =newTimer(10, this::doUpdate);
    55.                
    56.                 ////////////////////////////////////////////////////////////////////////////////////////////////////
    57.                
    58.                 public JPanelImpl(){
    59.                         addMouseMotionListener(this);
    60.                        
    61.                         this.timer.start();
    62.                 }
    63.                
    64.                 ////////////////////////////////////////////////////////////////////////////////////////////////////
    65.                
    66.                 @Override
    67.                 publicvoid mouseDragged(finalMouseEvent e){
    68.                         this.point.setLocation(e.getX(), e.getY());
    69.                 }
    70.                
    71.                 @Override
    72.                 publicvoid mouseMoved(finalMouseEvent e){
    73.                         this.point.setLocation(e.getX(), e.getY());
    74.                 }
    75.                
    76.                 @Override
    77.                 publicvoid paintComponent(finalGraphics graphics){
    78.                         final
    79.                         Graphics2D graphics2D =Graphics2D.class.cast(graphics);
    80.                         graphics2D.setColor(Color.BLACK);
    81.                         graphics2D.fillRect(0, 0, getWidth(), getHeight());
    82.                        
    83.                         if(this.bufferedImage!=null){
    84.                                 graphics2D.drawImage(this.bufferedImage, 0, 0, getWidth(), getHeight(), null);
    85.                         }
    86.                        
    87.                         finalString string ="Hello, World!";
    88.                        
    89.                         finalint x =this.point.x-(graphics2D.getFontMetrics().stringWidth(string)/2);
    90.                         finalint y =this.point.y;
    91.                        
    92.                         graphics2D.setColor(Color.GREEN);
    93.                         graphics2D.drawString(string, x, y);
    94.                 }
    95.                
    96.                 ////////////////////////////////////////////////////////////////////////////////////////////////////
    97.                
    98.                 privatevoid doUpdate(@SuppressWarnings("unused")finalActionEvent e){
    99.                         repaint();
    100.                 }
    101.                
    102.                 ////////////////////////////////////////////////////////////////////////////////////////////////////
    103.                
    104.                 privatestaticBufferedImage doCreateBufferedImage(){
    105.                         try{
    106.                                 return ImageIO.read(newURL(";));
    107.                         } catch(final IOException e) {
    108.                                 return null;
    109.                         }
    110.                 }
    111.         }
    112. }
    113.  
    Runescape Gambling

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal