Clearing screen using java
In java, how can i clear the console screen while running the program?
It depends on what you mean by "using Java". There are Java libraries to do screen control.
Of course, there are different kinds of consoles, and some can't be cleared at all.
Similar Messages
-
Clearing the screen using java
hi
how to clear the screen using a java programfor (int n = 0; n < 24; n++) System.out.println();
Even better: don't clear the screen. The program I ran before your program printed out very important things. If your program throws away those important things then I will not like you or your program. -
Hi,
Is there anyway I can do a printscreen using java and then send the image over the network?
axlrose82hi,
I'm using java.awt.robot to do a print screen and trying to save the image or sending it over the network.
I tried to use applets but I got a "XTEST extension not installed on this X server: Error 0". Have you any idea how I can get around this?
Thanks for the help.
Sri.
My code for the applet is as follows:
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Robot;
import com.sun.image.codec.jpeg.*;
import java.awt.*;
import java.awt.Image.*;
import java.awt.image.BufferedImage;
import javax.imageio.*;
import javax.imageio.stream.FileImageOutputStream;
import java.util.*;
public class CaptureScreen extends JFrame{
JButton button1 = new JButton("ScreenCapture");
JButton button2 = new JButton("Quit");
Image img = null;
JFrame jframe = null;
JLabel jl = null;
ActionListener al = new ActionListener(){
public void actionPerformed(ActionEvent e){
String id = ((JButton)e.getSource()).getText();
if(id.equals("ScreenCapture")){
System.out.println("Screen capture button pressed");
getImage();
else if(id.equals("Quit")){
jframe.dispose();
System.exit(0);
public void getImage(){
System.out.println("Getting Image");
try {
Robot robot = new Robot();
// Capture the whole screen
area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage bufferedImage = robot.createScreenCapture(area);
Image image = toImage(bufferedImage);
jl.setText("get image");
try
{ // this try set turns the image into a jpg that is saved to the hard drive in the program dir.
FileOutputStream output = new FileOutputStream("Screen.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
encoder.encode(bufferedImage);
output.flush();
output.close();
catch(IOException e)
catch (AWTException awte) {
awte.getMessage();
//repaint();
// This method returns an Image object from a buffered image
public static Image toImage(BufferedImage bufferedImage) {
return Toolkit.getDefaultToolkit().createImage(bufferedImage.getSource());
public void paint(Graphics g){
public void Startproc(){
Container cp = getContentPane();
jframe = new JFrame();
jframe.setSize(500,500);
jframe.setLocation(10,100);
JPanel jp1 = new JPanel();
JPanel jp2 = new JPanel();
jl = new JLabel("Hello");
cp.setLayout(new FlowLayout());
button1.addActionListener(al);
button2.addActionListener(al);
jp1.add(button1);
jp1.add(button2);
jp2.add(jl);
cp.add(jp1);
cp.add(jp2);
public static void main(String[] args){
CaptureScreen capturescr = new CaptureScreen();
capturescr.Startproc();
capturescr.setSize(500,500);
capturescr.setVisible(true); -
How need to take screen shot of the screen using java.awt.Robot from javafx
1) I am displaying a Stage which is having an image and shapes in it and wanted to take the screen shot as and when i move the shape( which moves the stage ).
I am trying to java.awt.Robot, but i am getting headless exception. I used
@Override
public void start(final Stage primaryStage) {
// creating some images and shapes
Platform.runLater(new Runnable() {
@Override
public void run() {
// update();
public void update() {
if (stg.isShowing()) {
ScreenCapture.capture(stg.getX() + 2, stg.getY() + 2, (int) boundsOfCircle.getBoundsInParent().getWidth(), (int) boundsOfCircle.getBoundsInParent().getHeight());
magnifierImageView.setImage(new Image(SCREEN_SHOT_FILE));
public static void capture(final double x, final double y, final int width, final int height) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
System.out.println("x ="+x +" y = "+y +" width "+width +" height ="+height);
Robot robot = new Robot();
} catch (Exception e) {
System.out.println("exception arised while taking the screen shot ");
e.printStackTrace();
The above code throws headless exception.
2) The second issues is have a image & i am dividing the image into different rows and cols( images of same size ). This is i am doing using awt. and i wanted to load those different images into
javafx images . I am facing the issues when i try to load the images into javafx.hi,
click on print screen button in your keyboard.
open a word document and do Ctrl V .
*Reward points if it helped -
Secure key wont show up on screen using java
My secure key isn't working with my java even though java is up to date
Try a reset and see if that makes it appear.
Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up. -
How to create a Full screen in Java
Could some one help me in creating a full screen using Java such that we dont see any Taskbar or anything that is related to windows. For eg when we play a game we dont have access to those windows components.
The basic question is How to Lock the Desktop using Java Program and also how to capture the Key events Ctrl + Alt + Del and Alt + Tab and disable its actual functionality or change its action..Could some one help me in creating a full screen
using Java such that we dont see any Taskbar or
anything that is related to windows. For eg when we
play a game we dont have access to those windows
components. http://onesearch.sun.com/search/onesearch/index.jsp?qt=full+screen+java&subCat=&site=dev&dftab=&chooseCat=javaall&col=developer-forums
The basic question is How to Lock the Desktop using
Java Program and also how to capture the Key events
Ctrl + Alt + Del and Alt + Tab and disable its
actual functionality or change its action..You can't. -
How to clear the screen in java?
Hi,
How to clear the screen in java without using any loops?
ThanksJust paint with your background color to let the old paintings vanish.
-
Does anybody know how to Clear the screen in Java?
Hi guys,In C we use System Clear.
In java,which instructions shall i use in order to clear the screen?
Thanks,in advance!Of course you shouldn't do so anyway...
Terminal programs should coexist with all other terminal programs and not try to dominate the screen.
They should never clear the screen as this would remove output from other programs running in the same terminal. -
How to clear the DOS screen through java program
how to clear the DOS screen through java program
Just some Friday fun. Use the telnet program that comes with Windows and supports VT escape sequences.
import java.io.*;
import java.net.*;
public class AutoTelnet {
private static Socket s;
public static void main(String[] args) throws Exception {
Thread t = new Thread() {
@Override public void run() {
try {
s = new ServerSocket(5555).accept();
} catch (IOException ex) {
ex.printStackTrace();
t.start();
Process p = new ProcessBuilder("cmd", "/C", "start", "telnet", "127.0.0.1", "5555").redirectErrorStream(true).start();
t.join();
PrintStream ps = new PrintStream(s.getOutputStream());
ps.println("Screen will be cleared in 5 seconds");
ps.println("5");
Thread.sleep(1000);
ps.println("4");
Thread.sleep(1000);
ps.println("3");
Thread.sleep(1000);
ps.println("2");
Thread.sleep(1000);
ps.println("1");
Thread.sleep(1000);
ps.println("\u001b[2J");
Thread.sleep(5000);
} -
How to take a screen shot using Java
I'd like to get a screenshot while a user is playing a game such as Quake or Half-life. Is this at all possible using Java or do I have to stupe to using OS dependent functions?
MattIn SDK 1.3 there's a createScreenCapture method in the java.awt.Robot class.
-
SAP BO Report Scheduling and Save as report using Java SDK
Hi All,
We have a java product which is integrated with SAP BO using Java SDK and we have certain java screen through which we select report prompt values and webi report gets run.
Now we want to give a functionality to save report to BO repository.
When user select certain check box from java screen a separate copy of the webi report should get saved under default folder on BO repository.
Also, we want user to choose the scheduling option from java screen only (and not the one which we use from BI Launchpad) due to certain access restriction. User does not have access to BI Launchpad. Only he can run report by selecting values through Java screen.
If i need to create a separate screen for scheduling as well as saving webi report then also i am ok with it.
P.S. i guess we need to work on Java SDK level. But could somebody please help me with the right direction?
Let me know in case requirement is not clear.Hi Ketan,
As you are on version BI 4.0 SP5 and would be migrating to BI 4.1, the best SDKs to use would be the Restful Webservices SDKs.
You have the options to schedule a webi report with prompts as well as the save feature which you require.
Please refer to the webi restful guides avialble at
For BI 4.0 SP5
http://help.sap.com/businessobject/product_guides/boexir4/en/xi4sp5_webi_restful_ws_en.pdf
For BI 4.1 SP4
http://help.sap.com/saphelpiis_sbo41sp4wi-sdk/frameset.htm
Refer to the below blog to understand the Restfull Webservices SDKs.
http://scn.sap.com/community/restful-sdk/blog/2013/09/07/scripting-web-intelligence-the-restful-raylight-web-services--learing-it
More blogs on Rest are available at
http://scn.sap.com/community/restful-sdk/content#filterID=contentstatus%5Bpublished%5D~objecttype~objecttype%5Bblogpost%5D
You can find the samples from the below link
http://scn.sap.com/community/restful-sdk/content#filterID=contentstatus%5Bpublished%5D~objecttype~objecttype%5Bdocument%5D
You would need to refer to the community below in case you have concerns about Rest SDKs.
http://scn.sap.com/community/restful-sdk
Thanks,
Prithvi -
How to connect iseries green screen from java program
how to connect iseries green screen from java program to get the data in the DB files ,here the DB is DB2/400
Just some Friday fun. Use the telnet program that comes with Windows and supports VT escape sequences.
import java.io.*;
import java.net.*;
public class AutoTelnet {
private static Socket s;
public static void main(String[] args) throws Exception {
Thread t = new Thread() {
@Override public void run() {
try {
s = new ServerSocket(5555).accept();
} catch (IOException ex) {
ex.printStackTrace();
t.start();
Process p = new ProcessBuilder("cmd", "/C", "start", "telnet", "127.0.0.1", "5555").redirectErrorStream(true).start();
t.join();
PrintStream ps = new PrintStream(s.getOutputStream());
ps.println("Screen will be cleared in 5 seconds");
ps.println("5");
Thread.sleep(1000);
ps.println("4");
Thread.sleep(1000);
ps.println("3");
Thread.sleep(1000);
ps.println("2");
Thread.sleep(1000);
ps.println("1");
Thread.sleep(1000);
ps.println("\u001b[2J");
Thread.sleep(5000);
} -
What is function to clear screen ??
hi,
What i s function to clear screen .. for example in C-languse we use clrscr();
like that what is function in java to clear screen.. that is in command prompt window clearI dont thik u can do this...
since u are writing to a stream. so what ever is written is written...
but if u have any ur own component developed u can do this.
regards,
Karthik -
Im coding a simple login page using java, whereby user enteres name and password and followed by the diplay of the user's name and password. Does anyone know how to clear the screen after the login page form, so that the screen is clear when user input is displayed?
Hi,
Which UI are u using to display the login screen and the and the display screen??
You can use Form to display the login screen and to display the data user entered.
If u want to use canvas then u have to manually erase the contents.
Use the following code.
public void paint(Graphics g)
int width = getWidth();
int height = getHeight();
g.setColor(WHITE);
g.fillRect(0, 0, width, height);
Hope This helps You -
Clear screen Method / pause method?
Are there any clear screen methods or pause methods I can use in swing? I'm new to java and am attemting to write a simple applet with a few images on it, do these methods exist?
thanks!
ClayNot sure. But if you make the system read a byte the screen will pause until you press enter. This is a dos screen however. Something like this:
try
byte[] b = new byte[2];
System.in.read (b);
} catch (IOException ex) {}
Maybe you are looking for
-
Problem signature: Problem Event Name: APPCRASH Application Name: firefox.exe Application Version: 32.0.3.5379 Application Timestamp: 54224e2c Fault Module Name: ntdll.dll Fault Module Version: 6.1.7601.18247 Fault Module Timestamp: 521ea91c Exceptio
-
Portal runtime error in Subscription Link
Hi , I have subscription service running on our portal and notification mails are sent properly ,but there is a problem in the email links sent for subscibed document or folder. The link shown in the mail is as below <b>/irj/servlet/prt/portal/prt
-
Problem with forward using RequestDispatcher
Dear All Below is my code, which trying to use the RequestDispatcher.forward to go from a Servlet to a .jsp page. and use getServletContext().setAttribute("SvBio",vBio); to set an attribute It compiles finely but stuck at the forward request to the j
-
SOA Suite: startup errors from tip/esb.configuration.util
I have the following setup on Windows XP Pro: 1. Oracle Database XE 2. SOA Suite 10.1.3.1.0 - Advanced Install 3. Upgrade to SOA Suite 10.1.3.4.0 MLR#7 4. SOADEMO - runs very well; I can place orders that require approval and see audit logs fine. Upo
-
How to start a simple program?? help
i dunno how to start... i wanted to make a stackmat timer to my mobile phone (sony ericsson K750i),, and i don't have any idea how to do it.. can someone help me with this? thanks