close a jframe in java with an if statement
Jframe frame = new Jframe(); if(count==5){ frame.setVisable(Boolean.FALSE); frame.dispose(); }
Jframe frame = new Jframe(); if(count==5){ frame.setVisable(Boolean.FALSE); frame.dispose(); }
public static A fold(F f, A z, Iterable xs) { A p = z; for (B x : xs) { p = f.f(p).f(x); } return p; }
import java.time.LocalDate; import java.time.Period; class TestJava { public static void main(String[] args) { LocalDate currentDate = LocalDate.now(); LocalDate birthDay = LocalDate.of(1989, 2, 22); Period period = Period.between(birthDay, currentDate); System.out.println(“Age: “); System.out.println(“Years: ” + period.getYears()); System.out.println(“Months: ” + period.getMonths()); System.out.println(“Days: ” + period.getDays()); } } Output: Age: Years: 32 Months: 11 Days: 2
tableView.getItems().clear();
import java.util.Timer; import java.util.TimerTask; class TestJava { public static void main(String[] args) { Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { System.out.println(“Print in every second”); } }, 0, 1000);//wait 0 milliseconds before doing the action and do it every 1000ms (1 second) } } Output: Print in every second Print … Read more
import java.awt.Color; import java.util.Random; class TestJava { public static void main(String[] args) { Random rand = new Random(); // Java ‘Color’ class takes 3 floats, from 0 to 1. float red = rand.nextFloat(); float green = rand.nextFloat(); float blue = rand.nextFloat(); Color randomColor = new Color(red, green, blue); System.out.println(randomColor); } } Output: java.awt.Color[r=232,g=230,b=101]
Note: New size must be a float, not an int. label.setFont(label.getFont().deriveFont(newSize));
import javax.swing.JFrame; public class CreateWindow{ public static void main(String[] args){ JFrame frame = new JFrame(); frame.setSize(150,150); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle(“Test Frame”); frame.setVisible(true); } }
$ sudo update-alternatives –config java
sudo update-alternatives –config java