Richard Legué

Greenhorn
+ Follow
since Sep 19, 2016
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
5
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Richard Legué

@ Carey Brown: thanks for your help. Very clear. I get it now!

@ Rob Camick: 1. I didn't set them obviously (duh..); 2. Yes, more than once? 3. that's exactly what I tried to find out; 4. No I did not. I used other tutorial material and examples (more than a couple); Ref you last remark: I don't expect anything of other people. I'm just asking your platform for help. Don't offer it if you don't want to, but much appreciated if you do. Thank you Carey Brown.
2 years ago
@Carey Brown: Here is the code that I used and comes up with the centered components on the JPanel. Thanks for looking at it.


import javax.swing.*;
import java.awt.*;


public class FutureValueFrame extends JFrame {

     
   public FutureValueFrame(){
               initComponents();
   }
   
   private void initComponents(){
       setTitle("future Value Calculator");
       setSize(400, 400);
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       setLocationByPlatform(true);
       
           try{
           UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
           }
           catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e){
           System.out.println(e);
           }
       
      JPanel pane = new JPanel();
      pane.setLayout(new GridBagLayout());
      GridBagConstraints c = new GridBagConstraints();
      add(pane);
     
      JButton button = new JButton("Button1");
      c.gridx = 0;
      c.gridy = 0;
      c.ipadx=0;
      c.ipady = 0;
      pane.add(button,c);
     
      JButton button1 = new JButton("Button2");
      c.gridx = 1;
      c.gridy = 0;
      c.ipadx=0;
      c.ipady = 0;
      pane.add(button1,c);
     
      JButton button2 = new JButton("Button3");
      c.gridx = 0;
      c.gridy = 1;
      c.ipadx = 0;
      c.ipady = 0;
      pane.add(button2,c);
     
      setVisible(true);
   }
       

   public static void main(String[] args) {
   java.awt.EventQueue.invokeLater(new Runnable() {
       @Override
       public void run(){
       JFrame frame = new FutureValueFrame();
       }
   });
   }
       
       
}
   
2 years ago
After setting the LayoutManager to 'GridBackLayout', the component (JLabel) I add to the panel on row 0 (y = 0), column 0 (x = 0) centers on the screen; so the screen origin seems to be in the middle and not in the lefthand top corner of the screen as I expected it to be. Is this as it should be and can I (re)set the origin of the screen?  
2 years ago
After setting the LayoutManager to 'GridBackLayout', the component (JLabel) I add to the panel on row 0 (y = 0), column 0 (x = 0) centers on the screen; so the screen origin seems to be in the middle and not in the lefthand top corner of the screen as I expected it to be. Is this as it should be and can I (re)set the origin of the screen?  
2 years ago
Thanks for all your additional explanation. Very helpful and also showing that there's lots to be learned yet. By the way, the 'hidden' class name I found when running the piece of code Campbell Ritchie posted is sun.nio.fs.WindowsPath. Thanks again for your help.
3 years ago
I figured as much, but I could'nt find in the API what the (to me invisible) class was that implemented the Path interface to produce the Path objects. I read some related topics on the forum as well and now it's clear to me. Thanks for your help guys.
3 years ago
Studying the java.nio.file package, I came across the Paths class that has 2 static methods that both return a Path object. Looking at the API for Path, I read that this is an interface with the description : An object that may be used to locate a file in a file system. It puzzles me that Path - an interface (not meant to be instantiated and used as an object) - is used as object. It seems to me that Path could be - or should be - a regular class, while it is not using it's interface functionality of offering generic functionalities for inheritance and polymorphism. What am I missing here? I would appreciate your guidance on this.
3 years ago
Congrats, Bravo Zulu!
3 years ago
Thanks for you help. Learning all the time!
4 years ago
If I initialize a byte or short variable with a numeric literal - for instance 'byte x = 100', the compiler doesn't complain although a numeric literal is seen by de compiler as an int-type. I don't need a cast to make this initialization work. But when I'm passing a numeric literal as a parameter to a method that takes a byte, the compiler complains about 'incompatible types'. for instance - 'public void takeArgs(byte x){ }' called by 'takeArgs(100);' makes the compiler complain. Changing the method call in 'takeArgs (byte 100) makes the code compile. I'm confused; both examples have to do with initialization (right?) but are treated differenly. Can somebody tell me why this is? Thanks
4 years ago
Okay, I will. Thanks!
4 years ago
Thanks for the helpful reactions sofar. I know for sure that the 'g'-object in question appears to be an instance of the Graphics class, but is in fact a Graphics2D object. But the Graphics2D class is (in the API) also abstract, just like its superclass Graphics. So I'm still puzzled:
1. how can I have an object of an abstract class;
2. that uses a method (setColor) which - according to its API) - is an abstract method in the superclass Graphics (so has no body) and is not implemented in Graphics2D.
Call me thick, but I'm trying to understand how this works. Cheers!
4 years ago
The Graphics class (java.awt.Graphics) is declared as an abstract class and is the superclass of class Graphics2D and DebugGraghics. The Graphics method .setColor() is also declared abstract, so I expect this method has no body and no 'behavior'-influencing function within the Graphics class. The .setColor() method is also not defined in the Graphics2D class; in fact, this method is not to be found in the Graphics2D class at all. Still, if I call the method (Graphic g; g.setColor(Color.red)), it actually works!!?? That would mean that the .setColor() method of the Graphics class does have a body (is defined) and has a function. Can someone tell me why/how this works? Thanks.
4 years ago