Giter Club home page Giter Club logo

java-swing's Introduction

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;
       }
   }

java-swing's People

Contributors

ogu1208 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.