Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8350219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:14:59+00:00 2026-06-09T08:14:59+00:00

I’m trying to make a java RAT but atm I only have screen displaying.

  • 0

I’m trying to make a java RAT but atm I only have screen displaying. When I run it it displays the screen on the JFrame fine, but it keeps dragging the same image a little lower with each draw like this:
screen

Client:

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.Socket;
import java.util.zip.GZIPOutputStream;
import javax.imageio.ImageIO;

public class Client {

    public static void main(String[] args) {
        try {
            Robot robot = new Robot();
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            Rectangle screen = new Rectangle((int) toolkit.getScreenSize().getWidth(), (int) toolkit.getScreenSize().getHeight());
            Socket socket = new Socket("127.0.0.1", 25565);
            GZIPOutputStream out = new GZIPOutputStream(socket.getOutputStream());

            while(socket.isConnected()) {
                ImageIO.write(robot.createScreenCapture(screen), "png", out);
            }
            out.close();
        } catch (AWTException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Server:

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.zip.GZIPInputStream;

import javax.imageio.ImageIO;

public class Server {

    public static void main(String[] args) {
        try {
            ServerFrame frame = new ServerFrame();
            ServerSocket serverSocket = new ServerSocket(25565);
            Socket socket = serverSocket.accept();
            GZIPInputStream in = new GZIPInputStream(socket.getInputStream());
            BufferedImage image = null;
            while(socket.isConnected()) {
                image = ImageIO.read(in);
                if(image != null) {
                    frame.setBufferedImage(image);
                }
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

ServerFrame:

import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;

public class ServerFrame extends JFrame {

    private BufferedImage image;

    public ServerFrame() {
        setTitle("RAT");
        setSize(1920, 1080);
        setVisible(true);
        image = null;
    }

    public void setBufferedImage(BufferedImage image) {
        this.image = image;
        this.repaint();
    }

    public void paint(Graphics g) {
        if(image != null) {
            g.drawImage(image, 0, 0, this);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:15:01+00:00Added an answer on June 9, 2026 at 8:15 am

    For some reason the drawing of the screen capture in the g.drawImage(image, 0, 0, this); line, when drawing in the JFrame, begins to slide up and left when you view the frame maximized.

    Try extending ServerFrame from JPanel and adding it to a JFrame, that way you get an anchor in the top-left corner. You can add a JScrollPane in there too, so that you can navigate the whole panel with the screen capture.

    Here’s the code I used to replicate your situation, it captures the screen whenever a key is pressed. I renamed the ServerFrame class to ScreenCapture.

    Hope it helps.

    import java.awt.AWTException;
    import java.awt.Graphics;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.Toolkit;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.image.BufferedImage;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class ScreenCapture extends JPanel implements KeyListener {
    
        private BufferedImage image;
    
        public ScreenCapture() {
            setSize(1920, 1080);
            setVisible(true);
            image = null;       
        }
    
        public void setBufferedImage() throws AWTException {
            Robot robot = new Robot();
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            Rectangle screen = new Rectangle((int) toolkit.getScreenSize().getWidth(), (int) toolkit.getScreenSize().getHeight());
            this.image = robot.createScreenCapture(screen);
            this.repaint();
        }
    
        public void paint(Graphics g) {
            if (image != null) {
                g.drawImage(image, 0, 0, this);
            }
        }
    
        @Override
        public void keyTyped(KeyEvent e) {}
    
        @Override
        public void keyPressed(KeyEvent e) {
            try {
                setBufferedImage();
            } catch (AWTException e1) {
                e1.printStackTrace();
            }
        }
    
        @Override
        public void keyReleased(KeyEvent e) {}
    
        public static void main(String [] args) {
            ScreenCapture capture = new ScreenCapture();
    
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.addKeyListener(capture);
            frame.add(capture);
            frame.setSize(500, 500);
            frame.setVisible(true);
        }
    }
    

    EDIT

    Here’s a piece of code to wrap the image in a JScollPane.

    import java.awt.AWTException;
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.Toolkit;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.image.BufferedImage;
    
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    
    public class ScreenCapture extends JLabel implements KeyListener {
    
        private BufferedImage image;
    
        public ScreenCapture() {
            setSize(1920, 1080);
            setVisible(true);
            image = null;
        }
    
        public void setBufferedImage() throws AWTException {
            Robot robot = new Robot();
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            Rectangle screen = new Rectangle((int) toolkit.getScreenSize()
                    .getWidth(), (int) toolkit.getScreenSize().getHeight());
            this.image = robot.createScreenCapture(screen);
            this.setIcon(new ImageIcon(this.image));
            this.repaint();
        }
    
        @Override
        public void keyTyped(KeyEvent e) {
        }
    
        @Override
        public void keyPressed(KeyEvent e) {
            try {
                setBufferedImage();
            } catch (AWTException e1) {
                e1.printStackTrace();
            }
        }
    
        @Override
        public void keyReleased(KeyEvent e) {
        }
    
        public static void main(String[] args) {
            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
    
            ScreenCapture capture = new ScreenCapture();
            JScrollPane scroll = new JScrollPane();
            scroll.getViewport().add(capture);
            panel.add(scroll, BorderLayout.CENTER);
    
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(panel);
            frame.addKeyListener(capture);
            frame.setSize(500, 500);
            frame.setVisible(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.