Swing/AWT/SWT :: Create A New PanelLogin In Main And Use Method To Get Panel
Feb 16, 2014
I have two classes: main (with JFrame) and a panelLogin class with a method returning a panel with all login components..so I create a new panelLogin in main and use the method to get the panel, put it into my JFrame. But here the problem: on the loginPanel the ActionListener for the login-event, if the input is correct,the panel shall disappear and the main panel shall appear.Should I make some kind of top class, which handels the panels?
View Replies
ADVERTISEMENT
Feb 26, 2015
I've been writing classes over and over for school. So I create a class outside of my main class. I create a new constructor and then create objects from my main class. I hope that makes sense. So i use methods in that class to work with the object. So I have an object name I've created <dot> method name. So I can create objects and then use methods from the class, but I'm wondering can I create a method in my main class and use it on that object? I don't understand how to do that.
View Replies
View Related
Apr 1, 2014
When i click on the button from bottom panel, top panel need to be redrawn. But redrawing is not happening. It happens only when resizing the applet.
public class Graphics_Chart(){
public init(){
JScrollPane topPane = new JScrollPane(new ImagePanel2());
topPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
topPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
[code]...
View Replies
View Related
Apr 4, 2014
i have created two(displaypanel & buttonpanel) main panels in a JFrame and many child panels,one of the panel is for holding buttons and displaypanel mainly swap child panel as directed from buttonpanel, but the problem arises i cannot navigate from child panel to another child panel,
as i have made a button on one of a child panel and from button panel i add the childpanel to displaypanel.it is working but when i tried to navigate from the button which is on child panel nothing happened. "i have made a function in main form which swap the content of mainpanel (displaypanel) and in childpanel i have acces the function through object of mainform"
View Replies
View Related
Jan 20, 2014
How to create multiple Choices in one Panel? I need to create a program that will choose a number in these choices then it will display the words at the bottom.
E.g. "Two Thousand Fourteen"
"Three Thousand"
"Two Thousand"
Thanks1.JPG
View Replies
View Related
May 27, 2014
I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?
View Replies
View Related
May 27, 2014
I have to write a method called censor that gets an array of strings from the user as an argument and then returns an array of strings that contains all of the original strings in the same order except those with length of 4. For example if cat, dog, moose, lazy, with was entered, then it would return the exact same thing except for the words with and lazy.
Currently, my code so far just prints [Ljava.lang.String;@38cfdf and im stuck.
import java.util.Scanner;
public class censorProgram {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
System.out.println ("How many words would you like to enter?");
int lineOfText = input.nextInt();
[Code] ....
I have to make new string array in the method and return words without four letters in the main method
View Replies
View Related
Feb 13, 2014
I am just trying to test this array, for a locker combination program that involves classes...but the array is printing out the whacky numbers for the location. When I try to call the method in the main, it does not work. How do I call a method that exist within a class into the main method?
public class locker {
public static void main(String[] args) {
CombinationLock();
[code]....
View Replies
View Related
Apr 23, 2014
I currently have the code set up to iterate through objects and keep track of them but how do I do the same and draw the objects on the panel window? I'm confused on what to do and how to start it.
Here's the code I have so far, the 'Car' which I want to draw extends to another class which extends to GameObject. I currently have a 'draw()' method under the 'Car' class but nothing in the 'draw()' method yet. From what I understand i'm suppose to have a 'draw()' method under 'GameObjects' class also?
public class MapView extends JPanel implements IObserver, ActionListener{
JPanel myPanel;
private Timer timer = new Timer(5, this);
int x = 0;
int moveX = 2;
public MapView(){
super.setBorder(BorderFactory.createTitledBorder("Map:"));
[code]....
Mostly I don't understand how to go through the iterator again to paint the objects. Wouldn't I need to put another iterator under 'paintComponent()' or can it be done under 'update()' ?
how to get some shapes from the GameObjects onto my panel.
View Replies
View Related
Oct 31, 2014
I've created a chat program, but now I need to show messages in different colors depending if the message is received or sent. I was wondering if I can use jlabel to do this but in this case I need that jlabels to scroll in a jpanel. how to do this or maybe using a rtf ?
View Replies
View Related
Sep 26, 2014
I have this panel in a nested class in the MainPanel class and it does not display, when I launch the applet, or more like, the two menus "LineColor" and "BackColor" from the nested class ColorPanel do not display .
This is the code:
package ui.panels;
import interfaces.Resettable;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.Panel;
[code].....
View Replies
View Related
Apr 27, 2014
My panel named panelIncomeInfo are not showing the components that I have added.
public class PayrollGUI {
private JPanel panelIncomeInfo = new JPanel ();
private JPanel panel = new JPanel ();
private JPanel panelPayCheckInfo = new JPanel ();
private JButton close = new JButton ("Close");
[Code] .....
View Replies
View Related
May 3, 2014
Program is not working. I want to use buttonPanel object in ColorAction class and the process is unknown to me .
package button;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonFrame extends JFrame
{
public JPanel buttonPanel;
[Code]...
View Replies
View Related
Oct 29, 2005
Is it possible to make Expand/Collapsable panels in Java without writing huge amounts of code? I want something like this Expand/Collapse How would I go about it?
View Replies
View Related
Aug 4, 2014
I am getting datas from user and checking it with database (MS SQL ) if it fits it is sweatching to new window. In new window I need to use again my database so I need to add connecting datas again. I would like to get them from login window. How to do that? I know theory but when I am writting code nothing works. Here is working code for login panel :
/*import java.awt.BorderLayout;
import javax.swing.*;
public class Login extends JFrame {
public String url;
public static void main(String[] args) {
Log frameTabel = new Log();
[Code] .....
View Replies
View Related
Apr 21, 2014
I have a program with a main panel JPanel that implements KeyListener. I added a JTextArea to which I added as the KeyListener: this, meaning the main panel. I made the JTextArea fill the entire main panel because I want to catch a key press anywhere in the main panel.I catch the key presses and the program does what I want it to.
I added a JToolBar to the program; it is working just fine.Now that I have two components on the main panel - toolbar and panel with textarea -, the textarea must have the focus before it will send the KeyEvent and call keyPressed(). I don't want to expect the user to click on the main window to get the program to start or after each time they use the toolbar.
I have tried calling both requestFocus() and requestFocusInWindow() on the textarea; neither call worked. I put the toolbar at PAGE_END instead of PAGE_START; this worked to allow the program to start but I don't want to have the toolbar at the bottom and once I clicked on a toolbar button, the textarea lost the focus.
I need to be able to give the textarea the focus when the program starts and after the user uses a toolbar button. (I suspect that if I solve the problem when the program starts, I can use the same method after handling a button press.)
View Replies
View Related
Jun 22, 2014
I want to switch panel on click of a button and code for switching panels is written in update method (Which gets called from notify observer of another class as part of Observer pattern.
unoGameController.playGame(playerFirst.getText(), playerSecond.getText());
playGame in Panel 1 of class 1 calls another class (class 2)and data comes in update method of class 1(Observer interface).
Now for switching panels code is in gameControllerDataProcessing . I am not able to switch the panels when this functionality runs.
However if i dont call the unoGameController.playGame(playerFirst.getText(), playerSecond.getText() and directly call the update method or directly write the switching panel code . then it works fine.
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if((!(playerFirst.getText().equalsIgnoreCase("") ||playerSecond.getText().equalsIgnoreCase(""))&&(!playerFirst.getText().equalsIgnoreCase(playerSecond.getText())) ) ){
unoGameController.playGame(playerFirst.getText(), playerSecond.getText());
[Code] .....
View Replies
View Related
Jan 13, 2014
Here's a class called Fibonacci
Java Code:
public class Fibonacci {
public static int fib(int n) {
if (n < 2) {return n;}
else {return fib(n-1)+fib(n-2);}
[code]....
it contains one method called fib() and one main method.If I would want to have the main method in another class than fib(), how would I write the two classes? Only cutting the main method from this class to another one doesn't work.My question is, is the reason it doesn't work because I then would have to have a constructor in the Fibonacci class, and create a Fibonacci object first which I then use the method on?
View Replies
View Related
Nov 23, 2014
In JButton's click event, I wanto to show a JPanel to print the message "Processing" on the screen. Before JButton's click logic end, hide the JPanel.
Actually, JPanel is not displayed. I do not know why.When msgPanel .setVisible(false); is commented out, JPanel is normally displayed .But do not know how to hide it when JButton's click logic is finished.
Here is the code.
loadBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JPanel msgPanel = new JPanel(rootFrame);
// Show the message JPanel
[Code] .....
View Replies
View Related
Sep 15, 2014
I am trying to read Point objects from .drw file which contains endpoints of line segments, and draw lines making a square on panel when I run the program. This is what I have got so far. how to get the points using array for drawing ?
// inside the method to read points objects from .drw file
try {
fos = new FileInputStream("square.drw");
oos = new ObjectInputStream(fos);
// creating an object of Point class
endPoints = new Point[sampleSize];
[code]...
View Replies
View Related
May 31, 2014
I am trying to make a Connect Four game with java swing, but I am getting an error with my attempt at making an multi D panel maker when I try to run it.
import javax.swing.*;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
[code]...
View Replies
View Related
Jul 23, 2014
I'm trying to make a TBG (Text Based Game) in Java for Android. Now, when I try to run it, it says No Main Method to run this program. The compiler also checks the program and tell me there are no errors.
View Replies
View Related
Oct 1, 2014
in java why main method is always static in nature...
View Replies
View Related
Jan 26, 2014
The idea is to create a program to add plants and retrieve plants from a Nursery. I created a class with the properties of the plants and also there is the class an Array list to keep track of the plants entered ( they will have to be printed later) (I am not too sure if adding a public class there is the best option.
The program will allow the user to pick and action and from there the code will do something. I don't want to have all the code inside 'main' The problem is in line 114.This is what I have so far.
Java Code:
package plant.nursery;
import java.util.ArrayList;
import java.util.Scanner;
/**Class to create a plant for a nursery.
public class PlantNursery
[code]....
View Replies
View Related
Apr 26, 2014
this is my program error occured run time,but compile sucessfully
{error msg-Error: Main method not found in class helloworldapp.HelloWorldApp, please define the main method as:
public static void main(String[] args)}
class HelloWorldApp
{
private int empno;
private float salary;
void setHelloWorldApp()
{
empno=12;
salary=1200;
[code]....
View Replies
View Related
Nov 17, 2014
I'm trying to call a method to my main method, but I can't seem to get it to work and it keeps resulting in a compile error.
import java.io.*;
import java.awt.Point;
import java.text.DecimalFormat;
import java.util.Random;
public class Chase {
public static void main(String args[]){
[Code] .....
View Replies
View Related