Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • PavSwag: BRAND NEW RSPS AUTOSCAPE,ORG FREE MBOX WHEN YOU GET 99 SKILL FOR DONATOR POINTS
      May 22, 2019, 01:52:56 PM
    • Duriall: Join the HYPE TRAIN! New Server - Varrock - Release is tomorrow. Join the discord and forums now for free items on release! [link]
      May 21, 2019, 04:47:56 PM
    • Riskdemon:[link] Varrock OSRS RSPS releasing May 22nd! Discord link provided!
      May 18, 2019, 11:43:14 PM
    • violence.:[link] Most addictive RSPS brand new just opend free m box to every new player
      May 18, 2019, 08:07:04 PM
    • LukrativeHD: Zenyte, the most anticipated RSPS of 2019! The server has been in development for over 2 years! Zenyte will be launching on June 7, 2019! Join our huge community on discord : [link]
      May 17, 2019, 11:18:39 AM
    • SnowRSPS: **Snow-PS | Custom & Improved RSPS | FREE $5 Scroll | Daily Giveaways, Updates & MORE!** **Site:** **<https://SnowRSPS.com><https://Snowscape.net>** **Discord:** [link] ```HTTP |FREE TO PLAY| -317 loading 602 graphics -GambleBots Fully Coded -Fullscreen -Prestige -AutoTrivia -AutoDonations -Custom ::NewHome -50+ Bosses -Unique Pets -Working Skills -Daily Giveaways -10+ Websites -(SnowPS.org|Snow317.com|& MANY MORE) -Staff Needed Always -Super Friendly Community -& We like to Update Weekly HOPE YOU COME N ENJOY! ``` **Facebook:**<https://facebook.com/snowrsps2012>
      May 16, 2019, 06:36:31 PM
    • PalidinoDH:[link]
      May 14, 2019, 10:53:37 PM
    • Coder Nick: ancientisle . com new OSRS server with heaps of content! raids etc!
      May 14, 2019, 04:19:55 AM
    • aXo: Are there any "vanilla" servers for the current OSRS style? Like, servers including tutorial island and all that, without much in the way of ridiculous customs and portals
      May 12, 2019, 05:28:13 PM
    • PavSwag: BRAND NEW RSPS AUTOSCAPE,ORG FREE MBOX WHEN YOU GET 99
      May 10, 2019, 03:28:22 PM
    • Blasta: Hey im available for staff positions want my discord? robzzd#1501
      May 08, 2019, 09:29:13 PM
    • Coder Nick: Brand new rsps ancientisle . com need players and staff!
      May 07, 2019, 09:42:54 PM
    • IceDynasty: LOG IN NOW FOR FREE DONOR! 4 GUYS ON LIMAS-SCAPE
      May 07, 2019, 06:53:08 PM
    • IceDynasty: [youtube]KJNP6Mpg09A[/youtube] CHECK NEW 614 RSPS
      May 07, 2019, 06:24:21 PM
    • Smokey_:[link]
      May 04, 2019, 08:37:40 PM
    • Smokey_: New toplists with unique incentive review system that requires no external libraries in an easy to use plug n play system
      May 04, 2019, 08:37:35 PM
    • dan v jad:[link]  Join us on Discord! [link]  Real OS Server - #178 Data
      May 04, 2019, 11:44:19 AM
    • PavSwag: Try out OSRS brand new server need STAFF autoscape,0RG
      May 04, 2019, 03:48:02 AM
    • Chassy13: this site is dead
      May 01, 2019, 04:50:57 PM
    • Shadowspkin: Cant believe this sites still alive. @Gerrjat email me at [link] if you want
      May 01, 2019, 10:15:22 AM

    Author Topic: Graphics Java  (Read 1531 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