Displaying files in java

Display files in java windows

Now I am in a need to display text along with running of the code side by side. Maybe your’s. Question: I’m trying to move my jframe to second display automatically in windows 10 but its not working, I’m using JDK8, and video drivers are upto date below is my code:

Display files in java windows

Hi I want to display files name in a windows with JFrame but it don’t work, I don’t know how to add a new element in arrayList for each files I’m short of idea.

import java.io.File; import java.io.IOException; import javax.swing.JFrame; public class InterfaceGraphique extends JFrame < private static final long serialVersionUID = 1L; public InterfaceGraphique() < this.setTitle("My first Window"); this.setSize(800,1000); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // First Graph Object Graph graph = new Graph(); String Path = "./TEST"; try < parcourir2(Path); >catch (IOException e) < e.printStackTrace(); >this.setContentPane(graph); this.setVisible(true); > public static void parcourir2 (String Path) throws IOException < String[] Name = ; Graph graph = new Graph(); File repertoire = new File(Path); File[] liste = repertoire.listFiles(); int y = 150; if (liste != null) < for (int i = 0; i < liste.length; i++) < if (liste[i].isDirectory()) < parcourir2(liste[i].getAbsolutePath()); >if(liste[i].isFile()) < Point Name[i] = new Point(liste[i].getName(),150,y,"normal"); graph.addPoint(Nom[i]); System.out.println(liste[i] + "\n"); Test.TestFile.Afficher(liste[i]); >y+=50 ; > > else < System.err.println( "Nom de repertoire invalide"); >> > 

and there is the class graph :

import java.awt.Graphics; import javax.swing.JPanel; import java.awt.Color; import java.awt.Font; import java.util.ArrayList; import java.util.List; public class Graph extends JPanel < private static final long serialVersionUID = 1L; Listpoints = new ArrayList(); @Override public void paintComponent(Graphics g) < System.out.println("Je suis exécutée !"); for (Point point : points) < if(point.getEtat().contentEquals("erreur")) < Font font = new Font("Courier", Font.BOLD, 20); g.setFont(font); g.setColor(Color.red); >else if(point.getEtat().contentEquals("normal")) < Font font = new Font("Courier", Font.BOLD, 20); g.setFont(font); g.setColor(Color.black); >else if(point.getEtat().contentEquals("valide")) < Font font = new Font("Courier", Font.BOLD, 20); g.setFont(font); g.setColor(Color.green); >g.drawString(point.getFichier(), point.getX(), point.getX()); > > public void addPoint(Point point) < points.add(point); >public static void main(String[] args) < @SuppressWarnings("unused") InterfaceGraphique ig = new InterfaceGraphique(); >> 

It’s the final step for my project it’s very important, thanks for help I search since a long time.

  1. None of your methods (other than main() ) should be static.
  2. It is rarely a good idea to extend JFrame.
  3. Your class InterfaceGraphique serves no useful purpose.
  4. rcourir2() should be an instance method of Graph.
  5. All of this should be done on the EventDispatchThread, not on the main thread. Your main should create a Runnable to run on the EDT, and all of the GUI stuff done in its run() method.
  6. In that run method, create a JFrame, create a Graph, add the graph to the frame, set its size or pack it, and make it visible.
Читайте также:  Safe to use javascript

Can Java display a dialog without changing the active window?, I’d like to display a modal (progress) dialog above a Frame , even if that Frame isn’t the active window. However, displaying a dialog

Java swing tutorial [02] — Display window at center of screen

Find the source code here -https://bushansirgur.in/java-swing-display-jframe-window-at Duration: 3:00

Java swing tutorial [01]

Find the source code here -https://bushansirgur.in/java-swing-display-basic-window-example Duration: 3:31

Creating another window for just displaying text + swing

I currently have a window frame with panels inside and am using it to run my program. Now I am in a need to display text along with running of the code side by side.

The problem with displaying it in the same window is that it minimizes the total screen area which I am using for input handling.

Thus I decided to create a dialog box and dump all the text inside.

This proved to be a bad decision as sometimes the output is really large and dialog boxes do not contain the scroll bar.

Can anyone tell me what’s the best way to proceed?

I just want suggestions to what should I try and do not need any code part for it as I would like to do that on my own 🙂

  • Create a new JWindow (or JFrame, one tutorial here: http://download.oracle.com/javase/tutorial/uiswing/components/frame.html)
  • Inside of it, create a new JTextArea and dump all your text there
  • to get the scrolling, create a new JScrollPane around your JTextArea. Tutorial: http://download.oracle.com/javase/tutorial/uiswing/components/scrollpane.html

You should follow tradition and use either:

  • One JFrame that will host your application and open any number of JDialog s your for your scrolling text etc.

JFrame is a top-level container and every application should have only one. You do not loose any functionality this way, and you stick with the standards, which will definitely make somebody’s life easier in the future. Maybe your’s.

Getting a JFrame to display floating on tiling window managers, You can then customize and add a JPanel with the layout and components you need in your application. The size of the window should be set

What is the best way to move JFrame to 2nd display in Windows 10

I’m trying to move my jframe to second display automatically in windows 10 but its not working, I’m using JDK8, and video drivers are upto date below is my code:

import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.swing.JFrame; import javax.swing.JLabel; public class DualMonitor < public static void main(String. args) < GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); javax.swing.JOptionPane.showConfirmDialog((java.awt.Component) null, "Found : " + gs.length, "screen detected ?", javax.swing.JOptionPane.DEFAULT_OPTION); for (int j = 0; j < gs.length; j++) < GraphicsDevice gd = gs[j]; JFrame frame = new JFrame(gd.getDefaultConfiguration()); frame.setTitle("I'm on monitor #" + j); frame.setSize(400, 200); frame.add(new JLabel("hello world")); frame.setVisible(true); >> > 

Issue is resolved by using setLocationRelativeTo , setUndecorated and setExtendedState(JFrame.MAXIMIZED_BOTH) check below:

import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.swing.JFrame; import javax.swing.JLabel; public class DualMonitor < public static void main(String. args) < GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); javax.swing.JOptionPane.showConfirmDialog((java.awt.Component) null, "Found : " + gs.length, "screen detected ?", javax.swing.JOptionPane.DEFAULT_OPTION); for (int j = 0; j < gs.length; j++) < GraphicsDevice gd = gs[j]; JFrame dualview = new JFrame(gd.getDefaultConfiguration()); JFrame frame = new JFrame(); frame.setLocationRelativeTo(dualview); dualview.dispose(); frame.setUndecorated(true); frame.setTitle("I'm on monitor #" + j); frame.setSize(400, 200); frame.add(new JLabel("hello world")); frame.setExtendedState(JFrame.MAXIMIZED_BOTH); frame.setVisible(true); >> > 

Java Swing — Why is my first window not disposing/closing?, I’m wondering how would I change the display of the frame then? Should I use panels for each display i want? – data_pi. Jun 4, 2017 at 5:42.

Источник

How to display all the files in a directory using Java

Following example shows how to display all the files contained in a directory using list method of File class.

import java.io.*; public class Main < public static void main(String[] args) < File dir = new File("C:"); String[] children = dir.list(); if (children == null) < System.out.println( "Either dir does not exist or is not a directory"); >else < for (int i = 0; i< children.length; i++) < String filename = children[i]; System.out.println(filename); >> > >

Result

The above code sample will produce the following result.

build build.xml destnfile detnfile filename manifest.mf nbproject outfilename src srcfile test

The following is an another example to display all the files in a directory.

import java.io.File; public class ReadFiles < public static File folder = new File("C:\\Apache24\\htdocs"); static String temp = ""; public static void main(String[] args) < System.out.println("Reading files under the folder "+ folder.getAbsolutePath()); listFilesForFolder(folder); >public static void listFilesForFolder(final File folder) < for (final File fileEntry : folder.listFiles()) < if (fileEntry.isDirectory()) < listFilesForFolder(fileEntry); >else < if (fileEntry.isFile()) < temp = fileEntry.getName(); if ((temp.substring(temp.lastIndexOf('.') + 1, temp.length()).toLowerCase()).equals("txt"))System.out.println( "File = " + folder.getAbsolutePath()+ "\\" + fileEntry.getName()); >> > > >

The above code sample will produce the following result.

Reading files under the folder C:\Apache24\htdocs File= C:\Apache24\htdocs\android\bkp\end.txt File= C:\Apache24\htdocs\android\end.txt File= C:\Apache24\htdocs\cpp_standard_library\images\code.txt File= C:\Apache24\htdocs\java\Java - Data Structures.txt File= C:\Apache24\htdocs\java\Java - Inheritance.txt File= C:\Apache24\htdocs\scripts\easyui\changelog.txt

Источник

How to Display the Contents of a Directory in Java

Displaying the contents of a directory in Java can be accomplished using the File class. This class provides the listFiles method that returns a list of File objects for a given directory. The objects may represent files or subdirectories. To understand how to display the contents of a directory in Java, follow these four steps.

  1. Open your text editor and type in the following Java statements:Java Source for Display Directory ContentsThe program instantiates a File object and passes to the constructor the directory whose contents are to be displayed. Replace the directory shown with a directory on your file system that you know contains files and at least one subdirectory. The listFiles method returns an array of File objects. The program iterates through the array and tests each entry. A message is displayed indicating if the object is a file or a directory. The name of the entry is also displayed.
  2. Save your file as DisplayTheContentsOfADirectory.java .
  3. Open a command prompt and navigate to the directory containing your Java program. Then type in the command to compile the source and hit Enter .Compile Source for Display Contents
  4. Type in the command to run your program and hit Enter .Run Display Directory ContentsVerify that the output displays all files and subdirectories in the directory you specified in the File constructor parameter.
  1. How to Check Object Type in Java
  2. How to Create a Jar File in Java
  3. How to Compile Packages in Java
  4. How to Throw an Exception in Java
  5. How to Create an Exception Class in Java
  6. How to Use the super Keyword to Call a Base Class Constructor in Java
  7. How to Use the Comparator.comparing Method in Java 8
  8. How to Use System.in in Java
  9. How to Call an Interface Method in Java
  10. How to Add a Time Zone in the Java 8 Date/Time API
  11. How to Rethrow an Exception in Java
  12. How to Use the instanceof Operator with a Generic Class in Java
  13. How to Instantiate an Object in Java
  14. How to Filter Distinct Elements from a Collection in Java 8
  15. How to Create a Derived Class in Java
  16. How to Skip Elements with the Skip Method in Java 8
  17. How to Create a Java Bean
  18. How to Implement an Interface in Java
  19. How to Compare Two Objects with the equals Method in Java
  20. How to Set PATH from JAVA_HOME
  21. How to Prevent Race Conditions in Java 8
  22. How to Write a Block of Code in Java
  23. How to Display the Contents of a Directory in Java (this article)
  24. How to Group and Partition Collectors in Java 8
  25. How to Create a Reference to an Object in Java
  26. How to Reduce the Size of the Stream with the Limit Method in Java 8
  27. How to Write an Arithmetic Expression in Java
  28. How to Format Date and Time in the Java 8 Date/Time API
  29. How to Use Comparable and Comparator in Java
  30. How to Break a Loop in Java
  31. How to Use the this Keyword to Call Another Constructor in Java
  32. How to Write a Unit Test in Java
  33. How to Declare Variables in Java
  34. How to Override Base Class Methods with Derived Class Methods in Java
  35. How to Use Serialized Objects in Java
  36. How to Write Comments in Java
  37. How to Implement Functional Interfaces in Java 8
  38. How to Write Type Parameters with Multiple Bounds in Java
  39. How to Add Type and Repeating Annotations to Code in Java 8
  40. How to Use Basic Generics Syntax in Java
  41. How to Map Elements Using the Map Method in Java 8
  42. How to Work with Properties in Java
  43. How to Write while and do while Loops in Java
  44. How to Use the finally Block in Java
  45. How to Write for-each Loops in Java
  46. How to Create a Method in Java
  47. How to Continue a Loop in Java
  48. How to Handle Java Files with Streams
  49. How to Create an Interface Definition in Java
  50. How Default Base Class Constructors Are Used with Inheritance

Training Options

Course Catalog

Источник

Displaying files in java

Learn Latest Tutorials

Splunk tutorial

SPSS tutorial

Swagger tutorial

T-SQL tutorial

Tumblr tutorial

React tutorial

Regex tutorial

Reinforcement learning tutorial

R Programming tutorial

RxJS tutorial

React Native tutorial

Python Design Patterns

Python Pillow tutorial

Python Turtle tutorial

Keras tutorial

Preparation

Aptitude

Logical Reasoning

Verbal Ability

Company Interview Questions

Artificial Intelligence

AWS Tutorial

Selenium tutorial

Cloud Computing

Hadoop tutorial

ReactJS Tutorial

Data Science Tutorial

Angular 7 Tutorial

Blockchain Tutorial

Git Tutorial

Machine Learning Tutorial

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures tutorial

DAA tutorial

Operating System

Computer Network tutorial

Compiler Design tutorial

Computer Organization and Architecture

Discrete Mathematics Tutorial

Ethical Hacking

Computer Graphics Tutorial

Software Engineering

html tutorial

Cyber Security tutorial

Automata Tutorial

C Language tutorial

C++ tutorial

Java tutorial

.Net Framework tutorial

Python tutorial

List of Programs

Control Systems tutorial

Data Mining Tutorial

Data Warehouse Tutorial

Javatpoint Services

JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.

  • Website Designing
  • Website Development
  • Java Development
  • PHP Development
  • WordPress
  • Graphic Designing
  • Logo
  • Digital Marketing
  • On Page and Off Page SEO
  • PPC
  • Content Development
  • Corporate Training
  • Classroom and Online Training
  • Data Entry

Training For College Campus

JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week

Like/Subscribe us for latest updates or newsletter RSS Feed Subscribe to Get Email Alerts Facebook Page Twitter Page YouTube Blog Page

Источник

Оцените статью