ACM Graphics Program - How To Set Location Of Entire Window
Jun 15, 2014
I have one quick question. If you are extending the acm graphics program, how can you set the location of the entire window? All the set location methods within the graphics program only seem to set the location of graphical objects. I know with JFrames I can use the setLocationRelativeTo(null) to position the JFrame in the center. How to set the location of a graphics window.
how to put a console on a JFrame or on graphics window. I thought about simply using a JtextField however I don't have access to the readline command since it appears to me that it is only found in a Console Program. So basically I was wondering how to put up a console on JFrame so I can issue commands on it and watch graphical stuff happen on the same screen(minus where the console box is of course).
I am writing a small app to automate some actions on my computer this requires me to open an application and click on a button I am using
Process child0 = Runtime.getRuntime().exec("/home/user/application");
to do this. The problem is every time it opens at a different lcation on the screen so i cannot click on it using the robot class due to x,y coordinates being different every time. with selenium you can use .setlocation(x,y) method but how can this be done for other applications.
I have a question about how to delete only a certain amount of objects on screen in a graphics window. I have a method that will enable me to get rid of every object of the same type off screen, for example this method:
Java Code:
public void deleteTrees() { //clears all tree trunks and leaves for (Iterator<GRect> it = historyT.iterator(); it.hasNext();) { GObject gobj = it.next(); this.remove(gobj);
[Code] ....
That Will delete all trees.
Now In my main method I populate the screen with trees by doing this
My question is how to specify only deleting x amount of trees instead of the whole thing. I pretty sure I need to use something like history.remove(trunk) and to iterate through the amount of trees specified, but not sure how to implement that.
How to remove multiple objects that are onscreen in a java graphics program(specifically the one from the acm library). The clearAll works fine but I would like to keep the background in my frame. I just want to be able to do something like removing all the trees by typing in a phase into a console program. Here is a small snippet of code with details of what I am trying to achieve.
Java Code:
public void command(){ Dictionary dic=new Dictionary(); //dic list of all phases that will either make animations or remove things in a graphical window String line = readLine("Type here: "); if (line.equals(dic.clearActions[i])) { cleared=true;
So I am trying to make my hangman program to show graphics. Here is what I have so far. How do I make my variables in here into a graphics program?
import java.util.Scanner; import java.awt.*; import javax.swing.*; public class Hangman2 extends JFrame { public static void main(String args[]) { Scanner sc = new Scanner (System.in); Hangman2 gp = new Hangman2();
I am writing a program that will have a GUI window and displays an image when clicked on the image changes and clicked on again the image changes once more. Here is what i have.
I just started to learn Java Swing and I was trying to make a program that puts 2 images into the Frame window. The code itself doesn't have any errors but when I compile it gives a nullpointerexception, I checked the line with the error and it had to do with my image file but I can confirm the name is correct and I tried both using the path and the name of the image in the package but neither is working.
Error message: Exception in thread "main" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(Unknown Source) at ImageTutorial.<init>(ImageTutorial.java:25) at ImageTutorial.main(ImageTutorial.java:33)
I was working on this project, and I have everything working, except that it doesn't change the colors of the shapes in the other window. Here's the code to see what I'm doing wrong:
Java Code:
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JDemo { //Global Variables static Color color0 = Color.blue; //sets the value in the color0 variable to the method Color.blue . static Color color1 = Color.red; //Sets the value in the color1 variable to the method Color.red .
[Code] ....
The button0 is supposed to switch the color in window1, and button1 is supposed to switch the color in window0.
I am new to javafx I start using it instead of swing i used the scene builder for my forms the problem i faced i don't know how to have main screen with menu bar at top and depending the select from the menu it will open other windows and those window must be inside my window just like for example netbeans.
I don't need to open new window in separate i need all windows inside my main window and controlling over them minimize maximize perhaps.
I'd like to enable/disable a jpanel and it's entire contents in one fell swoop. I could of course call each component's .setEnabled() method, but I figured there must be a better way!
I have in my app a JTable. I would like to know how can i do to, when i click in a cell, my jtable paint the entire line of this cell. Here is what i did.
Method call: private void jTable1MouseClicked(java.awt.event.MouseEvent evt) { int row = jTable1.rowAtPoint( evt.getPoint() );// Don't know how to send this info through setDefaultRenderer. jTable1.setDefaultRenderer( Object.class, new RowRender() );
make the keylistener "listen" across the entire application? Currently whenever I've used it I have always attached it to something else, like a JTextField or the like. However that doesn't work all that well if I for example want to close down the current JDialog by pressing escape, because no object that has the keylistener attached to it is currently focused.
When I searched around for the answer if found similar questions on stackoverflow, but those seemed to focus on listening globally, even when the application itself is not focused, which isn't quite what I want.
Here is a simple piece of code that I'm currently experimenting with:
It's supposed to simply create a frame and give me a message whenever I press the A or D buttons, as well as notify me whenever they are released. As of currently it obviously doesn't work because the keylistener hasn't been attached to anything, but that's also where I'm unsure of how to proceed.
import javax.swing.*; import java.awt.event.*; public class menu { public static void main (String[] args){ JFrame frame = new JFrame("Menu"); frame.setVisible (true);
With the code below, I am trying to replace all regex matches for visa cards within a given text file.
My first test was with a text "new3.txt" exclusively containing the visa test card 4111111111111111. My objective was to replace the card with "xxxx-xxxx-xxxx-xxxx". This was successful.
However, when modifying the text file to include other characters and text before and after (ex: " qwerty 4111111111111111 adsf zxcv"), it gives mixed results. Although it successfully validates the match, it replaces the whole text in the file, rather than replacing solely the match.
When trying this search and replace with words (rather than a regex match), it does not have this behavior. What am I missing?
import java.io.*; import java.util.regex.*; public class BTest { //VISA Test private final static String PATTERN = "(?s).*4[0-9]{12}(?:[0-9]{3})?.*"; public static void main(String args[]) { try
I am having trouble with a jTable that I am using. I have set the listeners of the cells to save the information of the entire table every time they are modified, but run into the problem that the last modified cell does will not reflect its most recent value. The value will display visually, but not show up when I try to read from the cell. I have tried wrapping the saveProcGuide() call in swing's invokelater, but to no avail. I have marked the area where the problem becomes evident (values returned do not match those present in the visible table object). Below is the offending code:
// This is where I set up the listeners private void addProcGuideWithValues() { procTableModel.addRow(new Object[]{"", ""}); // document listener to be fed into editor/renderers for cells... DocumentListener docuListener = new DocumentListener() { public void changedUpdate(DocumentEvent e) { saveProcGuide();
I am trying to add scrollbars to my frame containing many different components and appearing when user resizes the window with the mouse adds pictures and admin of this online application adds labels or other components.
I want scrollbars to appear when the frame is resized and has components you don't see under so you can scroll down.
If I have for example this code, how i add the scrollbars when i make frame smaller ?
public class Test extends JFrame { private JPanel contentPane; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() {
I have an assignment on sorting, i kno i can get the sorting down but im having an issue with inputing the 512 ints in a file into an array. the instructor provided us with a file with 4 equal sets of ints. i tried to make my array of size [scan.nextInt()] and it cuts off the last 21 ints. and skips the first int. how can i get all of the integers in the text file into my array? this is what i have so far. if i hard code the array to size 50000 and then try to print the array it compiles but errors out when running it.
System.out.println("Please Enter text file in this format, XXXXX.txt :"); String file =fileName.nextLine(); Scanner scan = new Scanner(new File(file)); int [] data = new int[scan.nextInt()]; <-------here it skips first int int count= data.length; for (int i=0; i<data.length-1;i++) { data[i]=scan.nextInt(); } System.out.print(Arrays.toString(data));
rst 4 ints in output are: 501, 257, 390, 478...., supposed to be 492,501,390....and last ints are: ....88, 83, 79, 0 and supposed to be :88 83 79 77 76 72 71 71 66 57 56 48 48 41 33 30 23 23 18 17 15 13 9....it replace last ints with 0. why ? and how do i fix this. attached it the text file
I am trying to delete entire set of objects from my graphics program. Specifically I am trying to make a bunch of tree trunks, 10 in total, and then delete them all by pressing a button. I can manage to make the trunks but I can only delete one of them.
Below I can walk you through some of my code step by step to show you what I am trying to do:
Java Code:
public void drawTrunk(double width, double height, double xpos, double ypos) { trunks = new ArrayList(10); trunk = new GRect(width / 15.0, height / 3.0); trunk.setFilled(true); trunk.setFillColor(Color.orange);
[Code] .....
So basically I just would like to know how to make this work?
My problem occurs when I try to specify a file location as show below
//Open an output file that appends data and does not delete it FileWriter append_data=new FileWriter("C:hello.txt",true); //Make a file that cvan print data into it PrintWriter outputfile=new PrintWriter(append_data);
Apparently, I believe this is not the right way to set my own path for the file... How can I specify my file path.
One more question would be that suppose I want to specify the file location on Desktop. What the format for that?
I am passing input from the user to a method that will initialize an array of the data (scores in this case). The method is filling the entire array with the last input value.
array initializer method
Java Code:
public static float[] inputAllScores(float validScore) { float[] diverScores = new float[7]; for (int i = 0; i < diverScores.length; i++) { diverScores[i] = validScore; } return diverScores; } mh_sh_highlight_all('java');