Skip to content

Ogu1208/Java-Swing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Java-Swing

Java의 Swing을 μ΄μš©ν•œ GUI ν”„λ‘œκ·Έλž¨μ„ μ œμž‘ν•˜κΈ° μœ„ν•΄ κ³΅λΆ€ν•˜λŠ” repoμž…λ‹ˆλ‹€.
This is a repo to study to make a GUI program using Java's Swing. Please check the code for details.

I write this README.md in English to practice and improve my writing skills in English. If there's any problem with expression or grammar, let me know. Thank you :D

πŸ“Ÿ SwingDemo - Frame Study List>

πŸ’‘ MainFrame

Youtube url : https://www.youtube.com/watch?v=aIdIXsi1qTU

Result

image


πŸ’‘ Java GUI: Full Course β˜• (FREE) - Bro Code

Youtube url : https://www.youtube.com/watch?v=aIdIXsi1qTU

If you want to apply a kind of Listeners, you should declare the valuables global that you want to.

πŸ“ Frames

JFrame = a GUI window to add components to

image

πŸ“ labels

JLabel = a GUI display area for a string of text, an image, or both

image

πŸ“ panels

image

πŸ“ Buttons

JButton = a button that performs an action when clicked on

image

πŸ“ BorderLayout

image

πŸ“ FlowLayout

Layout Manager = Defines the natural layout for components within a container

μ™Όμͺ½μ—μ„œ 였λ₯Έμͺ½μœΌλ‘œ 배치되며 였λ₯Έμͺ½μ— 더 이상 곡간이 μ—†μœΌλ©΄ λ‹€μŒ μ€„λ‘œ μžλ™ λ°°μΉ˜λ˜λŠ” 게 νŠΉμ§•μž…λ‹ˆλ‹€. 일반적으둜 ν”Œλ‘œμš° λ ˆμ΄μ•„μ›ƒμ€ νŒ¨λ„μ— λ²„νŠΌμ„ λ°°μ—΄ν•˜λŠ” 데 μ‚¬μš©λ˜λ©°, 기본적으둜 κ°€μš΄λ° μ •λ ¬μž…λ‹ˆλ‹€.
They are laid out from left to right and automatically move to the next line when there is no more space on the right.
A flow layout is generally used to arrange buttons in a panel, center aligned by default.

image

πŸ“ GridLayout

Layout Manager = Defines the natural layout for components within a container

GridLayout = places components in a grid of cells.

Each component takes all the available space within its cell, and each cell is the same size

image

πŸ“ JLayeredPane

JLayeredPane = Swing container that provides a third dimention for positioning components ex. depth, Z-index

image image

πŸ“ Open a New Window

image image

πŸ“ JOptionPane

JOptionPane = pop up a standard dialog box that prompts users for a value or informs them of something

tistory - JOptionPane 자주 μ“°λŠ” λ©”μ†Œλ“œ 정리

image

πŸ“ textField

image

πŸ“ checkBox

JCheckBox = a GUI component that cat be selected or deselected

Set the Icon of the checkbox. If checkbox is selected, the icon changes to the other. You can do so by using the method setSelectedSIcon().

image

πŸ“ radio buttons

JRadioButton = One or more buttons in a grouping in which only 1 may be selected per group

We can limit the choice selection to only one item by putting them within the same grouping.
To do so, use ButtonGroup and add the items to it.

image

πŸ“ combo boxes

JcomboBox = A component that combines a button or editable field and a drop-down list

You should use the wrapper class if you need to store a permitted type.

image

πŸ“ sliders

JSlider = GUI component that lets user enter a value by using an adjustable sliding knob on a track

To change the text of label according to the sliders's value, implements the ChangeListener and overrides the method statechanged(ChangeEvent e).
And you should add .addChangeListener to item that you want to adjust.

image

πŸ“ sliders

JSlider = GUI component that lets user enter a value by using an adjustable sliding knob on a track.

To change the text of label according to the sliders's value, implements the ChangeListener and overrides the method statechanged(ChangeEvent e).
And you should add .addChangeListener to item that you want to adjust.

image

πŸ“ progress bar

progress bar = Visual aid to let the user know that an operation is processing

If you want to simulate the progress bar increasing over time, use Thread.sleep in try-catch.

image


πŸ’‘ Java Swing JTable Demo : JTable with .csv file - Bro Code

Youtube url : [https://www.youtube.com/watch?v=aIdIXsi1qTU](https://www.youtube.com/watch?v=Kmgo00avvEw)
image

create valuables

valuables

    JFrame jFrame;  
    JScrollPane jScrollPane;
    JTable jTable;
    String[] col;  // JTable col
    Object[][] data;   // data array to input to the table

Main Constructor

You should read file, process the data, and put them into Object[][] data Array. We'll define this work with the method getData()
Get data using the method getData(). In Main Constructor, create a JFrame, JTable, JScrollaPane. You should create jScrollPane like this. jScrollPane = new JScrollPane(jTable); because we want to add scroll to the dable. Next, Add jScrollPane to jFrame, and add properties of jFrame as below. Note the use of pack();

   Main() {
        jFrame = new JFrame("JTable Demo");
        col = new String[] {"Accounts", "Amount"};
        data = getData();
        jTable = new JTable(data, col);
        jScrollPane = new JScrollPane(jTable);
        jFrame.add(jScrollPane);
        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        jFrame.pack();
        jFrame.setVisible(true);
    }
    

Object[][] getData(){}

Specify the path to the file and read it line by line using BufferReader and FileReader.
First, read line by line to the end of the file using a while statement and add it to the Arraylist.
After that, we use split to count how many columns it has. Create an Object[][] with the size obtained above.
Looping through the for statement, each line is separated with split , and put them.
Now eturn the data.

 Object[][] getData () {
       try {
           String path = FileSystemView.getFileSystemView().getDefaultDirectory().getPath();
           BufferedReader br = new BufferedReader(new FileReader(path + "/bills.csv"));
           ArrayList<String> list = new ArrayList<>();
           String str = "";
           while ((str = br.readLine()) != null) {
               list.add(str);
               System.out.println(str);
           }

           int n = list.get(0).split(",").length; // how many clumns
           Object[][] data = new Object[list.size()][n];
           for (int i = 0; i < list.size(); i++) {
               data[i] = list.get(i).split(",");
           }
           br.close(); // close file
           return data;

       } catch (Exception e) {
           e.printStackTrace();
           return null;
       }
   }

About

This is a repo to study to create a GUI program using Java's Swing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages