Christian Halme

Greenhorn
+ Follow
since Aug 22, 2013
Merit badge: grant badges
For More
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Christian Halme

thanks, now I read a little more I understand how it works
10 years ago
thanks everybody, its working now.
I have a new problem.
since there's no command pack for JPanel, how do
I size JPanel so it fits my painting from Graphics method.
Is there some similar command to as pack() for JFrame I could use.
I tried with

without any success.
My class for JPanel looks like this
10 years ago
Hello

Iam making a program that works like a clock or timer.
The gui is on one JPanel and the analog clock on another.
My class handles three JPanels
the layout is similar to the below



I dont know how to choose which JPanel
to choose when using paintComponent method,
i want to paint to graphics JPanel.

please can someone help
10 years ago
Thanks everybody, now I think I know better how to do
10 years ago
Ok thanks, i will try to use several panels. one for graphics and one for the swing components.
10 years ago
It seem like theres no call to paintComponent method, i just don't understand why???




10 years ago
Thanks for the answers

I dont understand how I can write with the Graphics class on the same JPanel as I use swing components on or should I use different layers and which layers do I need in that case.
Where should my paintComponent method be?, should it be in the same class (MakeGUI) or should I have a class of its own like I have now (PlotGraphics).
Iam a little bit confused about these things
10 years ago
Hello

Iam programming a program which shows the current time as an analog clock, which i construct with the graphics class.
My GUI consists of buttons to set time, start clock or timer from the swing components.
Now I have been reading about java graphics class, iam not sure if it is OK to have both the GUI and graphics on the same layer (JPanel)
and where to implement the graphics methods.


10 years ago
Ok thanks I read your link and I understand that I can have more arguments or methods when im initialize instances, now i understand why it wont work
10 years ago
Hello

Just wanted to say that I managed to get it work.
The compiler wont complain at all if I instantiate by=
JButton button = new JButton();
but if I wright
JButton button;
button = new JButton();
the compiler starts complaining about insert curlybrackets and or missing ;
in the end of line, even if everything is OK.
now I believe there's some bugs on eclipse for ubuntu,
anyone who has experienced something similar?
10 years ago
Thanks for your reply.
I have been trying with the curly brackets also, but it wont compile anyway.
I never needed the curly bracketws before in my programming when declaring an boolean
variable or instantiating JButton's, I believe there has to be some compiler error going on.
10 years ago
Hello

Iam quite new to programming, so iam learning a little about OOP in general and started off with java.
I have been doing a program that takes in system time and converts it to analog time which I plot on
the monitor with graphics class and the appropriate functions.
The program is still far away from finished, but i get stucked and don't know how to continue.

there are four different classes:
Frame3 that's my main class.
GraphicsPlot is where I want to plot all the graphics.
MakeGUI from here I make the GUI to control the program flow.
TimeTick handles the Timer and TimerTask, to control the timing.

Iam programming with eclipse on my ubuntu 12.04 and I got various error messages from the IDE
all the time.

see the code below =

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

package clock;

import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.Timer;

import javax.swing.*;

//Class handles the GUI, for control flow of program.
public class MakeGUI extends JFrame
{

static int height, width;

JButton Enter;
JButton Set;
JButton StartTimer;
JButton StartClock;
JTextField TextField;
Timer tick;
JPanel pane;


Boolean clocksw; // Syntax error on token ";", { expected after this token, clocksw will function as a switch between timer or clock function


pane = new JPanel();
Enter = new JButton("Enter Value");
Set = new JButton("Set Value");
StartTimer = new JButton("Start Timer");



[size=18]S[tt]tartClock = new JButton("Start Clock"); //Syntax error, insert "}" to complete Block


public MakeGUI()
{
super("My Timer");
Toolkit toolkit = Toolkit.getDefaultToolkit();
height = toolkit.getScreenSize().height;
width = toolkit.getScreenSize().width;

setBounds(height/8, width/8, height/4, height/4);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}

public int getMonitorHeight()
{
return height;
}

public int getMonitorWidth()
{
return width;
}



public void createGUI()
{



StartTimer.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)
{
clocksw = false;
}
});

StartClock.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)
{
clocksw = true;
}
});

Set.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)
{

}
});

Enter.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)
{

}
});


}

}

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10 years ago