How To Pass Main Arguments On Execution To Swing Component

Aug 4, 2014

I wish to use args passed to main(String[]) during application execution to a Swing component.

In a simple example, assume args passed are: a b c d

And here is the result I look for:

package argsinswing;
import javax.swing.JOptionPane;
public class ArgsInSwing {
public static void main(String[] args) {
String str1 = args[0];

[Code] ....

View Replies


ADVERTISEMENT

Pass Arguments From Main To Paint Method

Feb 5, 2015

I want to take command line arguments and pass them to a paint method. This is a test program that will just draw some equations. How can I get the input array clinputs[] to be used in public void paint( Graphics g) ?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LinePlot extends JFrame {
public LinePlot() {
super( "Line Plot" );
setSize(800,600);

[Code] .....

View Replies View Related

Method Is Declared To Take Three Arguments - Only Two Arguments Pass On Program Call

Jun 9, 2014

A method is declared to take three arguments. A program calls this method and passes only two arguments.Will it take the third argument as

1 null
2 void
3 zero
4 Compilation error

View Replies View Related

How To Write A Constructor Where Can Pass 1 Or 2 Arguments

Apr 6, 2014

I am looking to write a constructor (in a herited class) to initialize the name of a single piece and its orientation using values ​​passed as parameters. If no value is given for guidance , it returns "none" , I do it in this way but i am not sure it is the right way:

public SimplePiece(String piece,String d){
super(piece);
if(d == null){
guidance = "none";
}else{
guidance = d;
}
}

What do you sugger me to do to get the right code .

View Replies View Related

Two Ways To Pass Arguments To Methods

Nov 14, 2014

I have a test that covers Objects & Classes, Importing Classes and Polymorphism. One of the essay questions will be: Explain two ways to pass arguments to methods and give examples. I was reading the book and found Pass by Value and Pass by Reference. Is this the two ways to pass arguments?

View Replies View Related

Swing/AWT/SWT :: Panel Doesn't Refresh When New Component Added If Smaller Than Largest Visible Component

Jan 26, 2014

I have a JPanel that's using a simple GridBagLayout.

JPanel panel = new JPanel();
GridBagLayout qPanelLayout = new GridBagLayout();
qPanelLayout.columnWidths = new int[] { 0 };
qPanelLayout.rowHeights = new int[] { 0 };
qPanelLayout.columnWeights = new double[] { Double.MIN_VALUE };
qPanelLayout.rowWeights = new double[] { 0.0 };
panel.setLayout(qPanelLayout);
componentCount = 0;

Based on user input I am adding sub-panels to the panel. These sub-panels may vary in height. They take up the full width of the Panel.

public void add(Component comp) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(2,2,2,2);
gbc.gridx = 0;
gbc.gridy = componentCount++;
panel.add(comp, gbc_questionPane1);
}

The odd behaviour I'm seeing is that if the height of the new sub-panel I'm adding is less than the height of the largest sub-panel currently displayed then the main panel does not repaint. If its height is equal or greater then the Panel does repaint, and any sub-panels that were added but not visible before are now painted. What have I missed?

View Replies View Related

Execution Of Swing Application On Another PC

Apr 6, 2014

I am writing a Java Swing GUI application on my pc. I have to give this application to my cousin with another pc, where he is not aware of programming. then how can he execute that application? are there any ways of skipping the "javac" and "java" procedures while executing the app on his computer?

I am using win7 x86 and same at my cousin's place. I am also using eclipse-kepler sr1 ide for app development.

Are there any easy ways of automating this "javac" and "java" process(compilation and execution)? something like...scripting?

View Replies View Related

Swing/AWT/SWT :: Application Just Stop Itself During Execution

May 18, 2014

I made a check4 application with Java.It correctly works but sometimes the application just stop itself during the execution.I never had a problem like this. The application just stop itself and i can't even quit using the closing button..

View Replies View Related

Swing/AWT/SWT :: Adding ActionListener To Button Component?

Mar 7, 2014

Can I add actionListener to a button component without creating a reference to it? Look at my code below:

public void init() {
setBackground(Color.red);
//Create the layout
setLayout(new BorderLayout(20, 5));
//Add buttons
add("North", new Button("Red"));
add("South", new Button("Yellow"));
add("East", new Button("Cyan"));
add("West", new Button("Magenta"));
add("Center", new Button("White"));
}

Or should I just do the usual instance.addActionListener(this) like myButton.addActionListener(this)?

View Replies View Related

Swing/AWT/SWT :: How To Come Up With GUI Application Involving List Component

Feb 1, 2014

I am learning Java on my own and I am taking on very small project by myself for fun, and I'm just stuck on this small part of the project.
So I have created a text file that contains a small list of toy names and prices, like:

Barbie, 12.95
Lego, 15.99
Hot Wheels, 5.00
Power Rangers, 6.49

And what I would like is my application to read the contents of the file and store the toy names in a list component. And then I want to be able to select a toy name from the list and add it to a shopping cart that is a list component as well. I want to the application to have menu items and buttons to allow me to remove items from the shopping cart, clear the shopping cart of all selections, and check out. When I check out, the application should calculate and display the subtotal of all the toy names in the shopping cart, the sales tax (which can just be 8 percent of the subtotal), and the total.

View Replies View Related

Swing/AWT/SWT :: Change Location Of Component Using Grid Bag Layout

Jun 13, 2014

How to change the location of a grid bag positioned component after it's already been added to the layout earlier?

Example is if I want component 1 to change from row 1 to row 2.

View Replies View Related

Swing/AWT/SWT :: How To Drag And Drop Component Within Layout Manager

May 28, 2014

For example, say I have I BoxLayout with a few JButtons in it. How could I make it such that I could drag a JButton such that it could be in front or behind the others?

I've thought about using ComponentMover and just switching to a null layout right before moving it and switch it back right after like bellow, but I'm not sure how to make it keep the change in order.

import java.awt.LayoutManager;
import java.awt.event.MouseEvent;
public class LayoutComponentMover extends ComponentMover
{
private LayoutManager layout;

[code]....

View Replies View Related

Swing/AWT/SWT :: Replace Dropdown Of JComboBox By Another Component Like JTable?

Jan 29, 2015

My question is related to combo boxes. A combo box in general is a text field with a dropdown list. I would want to know if we can replace hthe dropdown List by an other component, for example a JTable component.

View Replies View Related

Pass A Value From Main Class To Another Class

Feb 5, 2015

THIS IS MY MAIN CLASS:

Java Code:

import java.io.FileNotFoundException;
public class PrimaClasse {
public static void main(String[] args) throws FileNotFoundException {
SecondaClasse oggettoSeconda = new SecondaClasse();
oggettoSeconda.controlloNomi();

[code]....

Now it's working and from the main class i can controll the second class BUT. i want that is the main class that ask the user name, and i want pass that value to the second class. what code i must change?why eclipse wants me insert this import java.io.FileNotFoundException; and this throws FileNotFoundException for not give me an error?

View Replies View Related

Swing/AWT/SWT :: How To Pass Value And Add Item Into Combobox

Nov 15, 2014

createConnection();
try{
String str = "select * from stocks";
stmt = conn.prepareStatement(str);
ResultSet rs = stmt.executeQuery();

[Code] .....

I have this code in my another package , i want to call it in other package , but i dunno how to do that.

View Replies View Related

Swing/AWT/SWT :: How To Pass On Object To Event Listener

Sep 22, 2014

I’m teaching myself Java. I am a fairly proficient programmer in other languages, but this is the first OO language I’m doing.I have a question that is a bit hard to summarize. Or it should be: how can I pass on an object (or variable) to an event listener?

I am writing an application in which you can play a Sudoku game. I have separated the “logic” or the “model”(the classes with Sudoku data structures and methods to manipulate them) from the presentation (the view and the controller).The main method starts off as follows:

SudokuModel model = new SudokuModel();
SudokuView viewController = new SudokuViewController(model);

The first line creates class for the logic and the second line creates the class for the view and the controller. Since the view and the controller need access to the business logic, the model is passed on to the ViewController class.The SudokuViewController class creates the user interface in Swing and it handles the user input. For the user input I have created a number of listeners, like this:

table.addKeyListener(this);

Now these listeners need access to the model since they update it. However, as far as I’m aware the only parameter passed on to an event listener is the event itself. So these event listeners do not have direct access to the model, even though it is passed on to the constructor of the class SudokuViewController.

To circumvent this, I made model2 an attribute (variable) of the class SudokuViewController. The constructor of the class sets this variable as follows:

model2 = model;

Now the event listeners have access to model2, which they can manipulate.This works. However, I think it is an ugly solution, introducing an additional object (model2). I’d like to pass on the object named model to the event listener, but this doesn’t seem to be possible.

View Replies View Related

Swing/AWT/SWT :: Creating Several JPanels - Main Menu

Aug 17, 2014

I am tasked with creating several JPanels each of which has a title centered at the top. As such I have created parent panel that each panel extends. However, I am uncertain as to whether drawing the string on the panel or using a JLabel is the best solution. The panels might allow dynamic resizing...

View Replies View Related

Swing/AWT/SWT :: Execute Main Class Into A JButton?

Mar 10, 2014

how can i execute the main class into a JButton.

Example: Main Class

public class ComparativoV3{
public void loadComparative(String path){
}
public void compareDbs(){

[Code].....

how to set it up the private void CompareActionPerformed(java.awt.event.ActionEvent evt) as the ComparativeV3 main class, not giving it any argument, because the files are load from the arguments section & it reads diferent files with diferent arguments.

View Replies View Related

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 View Related

Java Swing Frame Can't Call On Other Methods From Main

Mar 25, 2015

I am trying to make a 2d graphical animation using the java swing classes in order to make a frame. I had a basic version working when all of the code was under the main method, but when I moved some into another method it broke it. With y understanding of java my code should work as I create a variable of the method containing the code and then assign the size and exit button. However this causes many problems such as my BeaconFrame method informing me that it is unused when I have used it. Here is my code:

import javax.swing.*;
import java.awt.*;
 public class BelishaBeacon {
  public void BeaconFrame() {
JFrame frame = new JFrame();
JPanel panel1 = new JPanel();

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Add Setbounds Inside Static Void Main In Java

Dec 31, 2014

I am making an application in java, inside static void main, i want to customize all buttons, text areas and want to put them on desired location inside application. I have tried to use setbounds but can not use it, how can i use it, or is there any other way or layout to make my application components customized layout.

View Replies View Related

Swing/AWT/SWT :: How To Return Values From A JForm To The Main Window On Close

Jan 26, 2014

I am making a java swing program. I have a main window that opens a JForm window when the user clicks a menu option. Then I have a button on the JForm that closes the window on click. However, I would also somehow like to make the JForm return values to the main window (according to the states of the selector components) when it is closed. How would I go about this? Currently my jForm is a seperate class called "NewGame", and inside the menu item mouse clicked method, I have the following code:

//open new game jform window
NewGame newGameWindow = new NewGame();
newGameWindow.setVisible(true);
newGameWindow.setLocationRelativeTo(null); //center window

Is there something I can add here to get the object's values upon the window's close? Or is there a way I can add that into the button clicked method on the actual jForm?

View Replies View Related

Swing/AWT/SWT :: Pass Object With Properties To Another Object

Jun 11, 2014

I am trying to find either some references to point me on the right track with passing an object with all of it's properties still in tact after it's been created. Currently I am trying to do this through an interface but it seems to just create a new object everytime without the properties. Example below :

import java.util.ArrayList;
import java.util.List;
public interface TPerson{
//public Person p = null;
}
class Thrower {
Person p;

[code]....

When I implement the interface on the other objects as soon as I call the setP method shown above it seems to just create a new one even though I pass the object to the method I want to use.

View Replies View Related

Two String Should Be Same But Execution Says Its Not

Feb 16, 2015

public class StringTest
{
public static void main(String args[])
{
String s1="hello";
s1=s1.concat("me");
String s2="hellome";
if(s1==s2) System.out.println("s1 and s2 has same referance");
if(s1.equals(s2)) System.out.println("s1 and s2 has same content");
}
}

Output is : s1 and s2 has same content

if after concatenation both string is stored in string pool it will refer to same memory location and other confusion is after any string operation like (concatenation , replace , substring) jvm creates a new string in which memory area..?? Heap or String pool.

View Replies View Related

Timeout For A Method Execution

Dec 22, 2008

I have a method "doSomething" which can take a while to be fully executed.

...
boolean bResult = false;
bResult = doSomething();
System.out.println("Result:" + bResult);
...

I would like to be able to stop the method execution after 10 seconds and continue the normal execution of my class. This means:

- If doSomething() is executed in 3 seconds for example, the System.out.println() statement shows the result of the method

- If doSomething() is executed in more than 10 seconds, after 10 seconds the method is stopped and the System.out.println() will always have false as result.

View Replies View Related

Execution Of Class File

Jan 20, 2015

I have got 2 classes in a source file, 1 real class and 1 test class with main() method. While executing with java command which class name should i write - real class or test class???

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved