Thursday, 22 September 2016

I give up on C#.

Well, during thinking about my ftp client i started to see that I lack a lot of knowledge from Java, mainly from design patterns. So for now I am changing my plans - at first I will learn design patterns and slowly write code of the client. I found really good lessons on caveofprogramming.com and in "Head first design patterns" AFter this I move to web dev. I know the basics of servlets and jsps so I will start with spring. It will be a long journey, wish me good luck!!!

Swing - populate JTable with files' names.

I am working on a gui for ftp client. I am using swing for gui and Apache Commons Net for ftp stuff. I still have problem with displaying icons in JTable. Later I will use MVC pattern. I am able to listen files' paths, size and modification date. Soon I will add more funcionality like changing directories, showing icons and basic operation on files and folder like: delete,cut,copy,change name, move but this all after I finish gui. Whole code on my github: GITHUB Code below:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.File;
import java.text.SimpleDateFormat;

import javax.swing.Icon;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.filechooser.FileSystemView;
import javax.swing.table.DefaultTableModel;

public class LeftPanel extends JPanel {

 private JTable table;
 private NavigationPanel backAndDriverPanel;

 private String[] columns = { "Path", "Size", "Last Modified" };
 private File file;
 private File[] filesNames;

 private final String DIR = "C:/";

 public LeftPanel() {

  Dimension dimension = getPreferredSize();
  dimension.width = 640;
  setPreferredSize(dimension);
  setLayout(new BorderLayout());

  // CREATING COMPONENTS
  table = new JTable();
  backAndDriverPanel = new NavigationPanel();

  table.setAutoCreateRowSorter(true);
  table.setFocusable(false);
  table.setRowSelectionAllowed(true);

  JScrollPane tableScroll = new JScrollPane(table);

  // ADDING COMPONENTS TO PANEL
  add(tableScroll, BorderLayout.CENTER);
  add(backAndDriverPanel, BorderLayout.PAGE_START);

  createTableModel();

 }

 public void createTableModel() {

  // DATE FORMAT
  SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

  file = new File(DIR);

  filesNames = file.listFiles();

  DefaultTableModel model = (DefaultTableModel) table.getModel();
  model.setColumnIdentifiers(columns);

  // LIST OF ROWS
  Object[] row = new Object[3];
  for (int i = 0; i < filesNames.length; i++) {

   row[0] = filesNames[i].getAbsolutePath();
   row[1] = filesNames[i].length();

   // CONVERTING FROM MILISECONDS TO NORMAL DATE
   row[2] = sdf.format(filesNames[i].lastModified());

   model.addRow(row);
  }

  // SETING EDITABLE TO FALSE
  for (int i = 0; i < table.getColumnCount(); i++) {

   Class<?> col_clas = table.getColumnClass(i);
   table.setDefaultEditor(col_clas, null);
  }

 }
}

via GIPHY

Friday, 16 September 2016

What to do now?

Today I'v decided that I am starting learning C#. Why? Because I want to learn how to read memory and toy with it. I was trying to do so with Java but it is hard. You have to use additional library and there was still a problem with accessing all processes. I was able to "hack" Minesweeper and change the time and number of mines. What about Java? Still in it. I will move to learning Spring. I don't know if learning two languages at once is a good idea but let's give it a shot. Also I'v borrowed two books.
1) Algorithms and data structures = Programs 2)Projecting and analysis computer algorithms.
happy coding!

Sunday, 11 September 2016

Today I was training algorithms and data structures on hackerrank.com. Here is one example:

Given a square matrix of size NxN, calculate the absolute difference between the sums of its diagonals.


import java.util.Scanner;

public class DiagonalAbsoluteSum {

 static int sumA = 0;
 static int sumB = 0;

 public static void main(String[] args) {
  Scanner in = new Scanner(System.in);
  int n = in.nextInt();
  int a[][] = new int[n][n];
  for (int a_i = 0; a_i < n; a_i++) {
   for (int a_j = 0; a_j < n; a_j++) {
    a[a_i][a_j] = in.nextInt();
   }
  }

  for (int i = 0; i < a.length; i++) {
   sumA += a[i][i];
  }

  for (int i = 0; i < a.length; i++) {

   sumB += a[i][a.length - i - 1];
  }

  System.out.println(Math.abs(sumA - sumB));
 }

}

Saturday, 10 September 2016

Hellow

Hellow my dear audience. The time has come to introduce myself. I am DEADALICE7000! Nice to meet ya.  Who am I? 24years old boy from country without prospects. I learn Java for 6 months. My dream is that I can get skilled with Java and get a job as a junior Java dev. You, my dear friemd might wonder why am I even posting this. Well, there are a lot of reasons: systematize my coding, share my opinion, taste, show my code. I will try to be a teacher for. You and me.  It is not like I am just programming. I like playing games a lot. Today I am starting adventure with a Dragonom Hunter. It looks funny. I am going to the gym. I dont wan't to be riped, or stuff like this. All I want is a strength.My favorite food is meat.  The bad thing about me is that I have a depression, schizophrenia disorder and high blood presure. When I wake up i take 6 pills, at the 12:00 i am taking another 2, and before sleep i take another 4. At the end I would like to mention that english language isn't my native, so please, ignore my mistakes.  Happy coding!