Is It Safe To Set Font With Absolute Parameters
Feb 14, 2015
I was wondering, if, for example I set font for my textarea like this:
area.setFont(new Font("Serif", Font.ITALIC, 18));
Is that last parameter, in this case 18, will be actually the same size for all users? Maybe I should avoid these absolute numbers?
View Replies
ADVERTISEMENT
Feb 14, 2014
Is /graphics/image.png a relative path or absolute path?
View Replies
View Related
Jul 10, 2014
I have situation where a user can request java server to send a value to an embedded device, and if the device is asleep, that value needs to be stored in a queue until the device wakes up and sends a position to java server, at which point the server checks if there is a value in the queue and if there is, it then sends that value to the device. The maximum size of the queue is 1 for now. And if the user makes continuous requests to java server, the old value is removed and the new value is added.
Initially I was looking into BlockingQueue, but the problem with that is, well, it blocks. queue.put(value) will block if queue is full, and queue.take() will block if queue is empty. I can't have something that blocks. When the device responds to server, server checks if value is in queue, if it is not then the server carries on the rest of its responsibility. Thus, I then entertained ConcurrentLinkedQueue. While queue.offer(value) and queue.poll(); allow you to add and remove values respectively from the queue without blocking, it does not allow you to set a maximum size limit of the queue. My queue must have a maximum size limit and it has to always be the newest value the user submits to the queue (where old values are removed).So this is what I came up with:
Java Code: class Unit {
private List<Integer> cmdQueue;
public Unit(){
cmdQueue = Collections.synchronizedList(new LinkedList<Integer>());
[code]....
I use Collections.synchronizedList, as I do here, do I still need to use synchronize as I did above?
View Replies
View Related
Jul 10, 2014
Implementation that proves that instance variables are not thread safe ....
View Replies
View Related
Apr 3, 2013
I have a multi-threaded application but one function (A) I need to call, that is provided by a third party, is not thread safe. I need to make parallel calls to function (A) so my only option is to start multiple process that I can call from each of my main applications threads.
To do this I created a RMI interface between a the client and the remote process. On the server side I start multiple processes each assigned a different port. On the client side I have a queue manager that connects to the processes I started and builds a queue of them. It passes the client to the threads as needed so they can function in parallel.
I am new to Java development and have the following questions:
1. Each of the server processes require an init function to be run before providing the service. How do I setup the server processes to continue to run in memory listening for a a service request after running the init processes.
2. Is there a better implementation of what I am trying to do?
View Replies
View Related
Jan 22, 2015
Are the static variables in servlet thread-safe?
View Replies
View Related
Oct 6, 2014
Write a method called largerAbsVal that takes two integers as parameters and returns the larger of the two absolute values. A call of largerAbsVal(11, 2) would return 11, and a call of largerAbsVal(4, -5) would return 5.
I have tried this code using methods in the Math Class but I am getting an error in Practice-it that says
Line 4
Your method's return type is void, which means that it does not return a value. But your code is trying to return a value. This is not allowed.
cannot return a value from method whose result type is void
return Math.max(Math.abs(Num1), Math.abs(Num2));
Here is my code. What I am doing wrong?
public static void largerAbsVal (int Num1, int Num2)
{
return Math.max(Math.abs(Num1), Math.abs(Num2));
}
View Replies
View Related
Apr 8, 2014
I'm a Java beginner and I've been trying to scan a file using the Java Scanner. I've tried searching online for this error and I only find people's questions who have entered an incorrect relative path. I'm entering in an absolute path and I'm using Eclipse Standard Edition on a 2013 MacBook Pro with Mavericks 10.9.2.
Anyway, the error message I'm receiving on Eclipse is: Exception in thread "main" java.lang.Error: Unresolved compilation problem: Unhandled exception type FileNotFoundException
at App.main(App.java:12)
public class App {
public static void main(String[] args){
String fileName = "/Users/Student/Documents/index.html";
[code]...
Why it cannot find this file. I've checked the absolute file path of index.html on my Mac and I've copied and pasted it into my code.
View Replies
View Related
Feb 19, 2014
I don't know how to define "abs." Here are the instructions:
The purpose of this exercise is to add to the IntClass class below a method, abs, that takes as its only argument an IntClass object and returns a new IntClass object representing the absolute value of the argument.
Define the desired method as a class method.
Define the desired method as an instance method.
In each case, use the main method to test your code.
There's two boxes of editable code. I'm having trouble with the first one, the one with "abs."
Here is more code:
My code goes here
}
Here's another box of code that they want me to fill out:
public class MainClass
{
public static void main( String[] args )
{
My code goes here...
View Replies
View Related
May 8, 2014
I read JEE6 doc and confused with : Does container managed entity manager (injected by PersistenceContext annotation) is thread-safe in stateless session bean in multiple-thread env?
See code below, if there are 2 requests to stateless sesion bean in 2 concurrent threads , is it using same Entity Manager Instance or not?
@Stateless(name = "HRFacade", mappedName = "HR_FACES_EJB_JPA-HRFacade-HRFacade")
public class HRFacadeBean implements HRFacade, HRFacadeLocal {
@Resource
SessionContext sessionContext;
@PersistenceContext(unitName = "HRFacade")
private EntityManager em;
[Code] .....
View Replies
View Related
Feb 25, 2014
I am new to applets and I am trying to create a program to display color and font. See my code below, I am getting some errors below.
import java.awt.Graphics; //program uses class Graphics
import javax.swing.JApplet; //program uses class JApplet
import javax.swing.JOptionPane; //program uses class JOptionPane
public class AdditionApplet extends JApplet
{
private double sum; //sum of values entered by user
private double average; //average of values entered by user
[Code] .....
java:11: error: cannot find symbol
Color skyBlue;
^
symbol: class Color
location: class AdditionApplet
java:12: error: cannot find symbol
Font sansFont;
[Code] .....
6 errors
Process completed.
View Replies
View Related
Apr 21, 2014
I am quite familiar with using JOptionPane and its various displayXDialog() methods and reasonably familiar with changing fonts.
I have a JOptionPane.displayMessageDialog() that is working fine but I decided to make the font larger.
I found an example from which I coded:
Font font = UIManager.getFont("OptionPane.font");
UIManager.put("OptionPane.font", new Font(font.getName(), font.getStyle(), 24));
font = UIManager.getFont("OptionPane.font");
JOptionPane.showMessageDialog(this, "Welcome to Mover", "About Mover", -1); // no icon
After the UIManager.getFont() call after the UIManager.put() call, font shows the new font size of 24, but the showMessageDialog() dialog still has the default font.
And yes I understand that, when this works, it will affect every JOptionPane in my program.
I also tried:
Font font = UIManager.getFont("OptionPane.font");
JOptionPane message = new JOptionPane("Welcome to Mover", JOptionPane.INFORMATION_MESSAGE);
JDialog dlg = message.createDialog("About Mover");
[Code] ....
This gave me a dialog with the default font and an unwanted icon.
So I tried
// both
Font font = UIManager.getFont("Dialog.font");
// and
Font font = UIManager.getFont("JDialog.font");
and planned to use that font in my setFont() call but font was null.
View Replies
View Related
Jun 18, 2014
How do i set a random font in java and random position on screen. I've got random color but cannot get the font and position to change except for two times.
import javax.swing.*;
import java.awt.*;
import java.util.Random;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JChangeSizeAndColor extends JPanel implements ActionListener {
private Random generator;
[code]....
View Replies
View Related
Feb 19, 2015
It's very simple, I've added an AWT component/control (specifically a Choice object to a Frame. It's a pop-up menu by any other name.
Above the pop-up, there's a label. I'm trying to change its font to no success.
* I create Label object called label1: Label label1 = new Label("This is a pop-up")
* I create a Font object called f: Font f = new Font("Times New Roman, Font.BOLD, 18)
* I apply the new font to the label: (in AFrame's constructor) label1,setFont(f)
When displayed the label's font seems to be stuck on Arialor something similar. Changing the point size however does have an effect.
import java.awt.Choice;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
/**
* Defines a 'pop-up' AWT control that will be added to AFrame.
* It extends Choice - I may need extra functionality later.
*/
public class APopUp extends Choice implements ItemListener {
// instance variables
int noi; // no of items
String selected; // item selected from choice
[Code] ....
View Replies
View Related
Feb 14, 2014
I am having some troubles with a program fileviewer where you must be able to change font style and size when pressing JButton "Set font". I have solved the most of the program and every menu button is working but I don't know how to set in FileListener class method to change the font when running in main class. Anyway, this is my FileListener class
Java Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.awt.Font;
public class FileListener implements ActionListener
[code]....
View Replies
View Related
Jan 20, 2014
The Font style constants are of int: int[] fontStyleList = new int[] {Font.PLAIN, Font.BOLD, Font.ITALIC};But what do I do when I want to add the names such as PLAIN etc. as the name of a menu item?
The following is not going to work, right!String[] parts = (fontStyleList[i].toString()).split("."); or String[] parts = ("" + fontStyleList[i]).split(".");rbStyle = new JRadioButtonMenuItem(parts[1]);
Is there another way to do this or should I just do another array with the names as a String?
View Replies
View Related
Jun 1, 2014
I'm trying to display a phrase in every font size from 6 thru 20. As it stands now, the code below cascades the phrase, sort of, down the frame, but the font size doesn't change.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JFontSizes extends JFrame implements ActionListener
{
JButton button = new JButton("Press Me");
String aPhrase = new String("This is a phrase.");
[Code] ......
View Replies
View Related
Jun 1, 2014
This is what I have thus far.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
[Code]....
The result looks something like this:
Button
This is a phrase.
This is a phrase.
This is a phrase.
This is a phrase.
etc.
View Replies
View Related
Apr 19, 2015
I'm new in Java. I try to create a menu with items like "Font size", "Font color" type of "font" how to create a menu with that options.
Java.jpg
View Replies
View Related
Jul 5, 2014
I wish to print the content of a JTextArea. I know I can do this with textarea.print(). However, I wish to print in a different font, font size and orientation from that of the JTextArea itself. I have been able to change the orientation by setting print attributes
PrintRequestAttributeSet printAttributes =
new javax.print.attribute.HashPrintRequestAttributeSet ();
printAttributes.add(javax.print.attribute.standard .OrientationRequested.LANDSCAPE);
And then using the textarea.print() method that allows me to set attributes. However, I haven't found any way to set the font and font size.
View Replies
View Related
Feb 10, 2014
So, I have a game. I would like to make a game where you press "start" and THEN it starts. Also, I want to have collision with triangles, not just squares. The way I handle collision right now is with if statements, if the object is within the other, game over.How would I do collision with triangles? Lastly, how do I set a high score? how to change fonts and font size in swing?
View Replies
View Related
Mar 9, 2014
I am having problem with the JRadio Buttons to change the font color in my code. What needs to be done? Also if I were to connect this GUI to another GUI and save font colors, how would I go about that?
package SystemandDesign.RISK;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.JFrame;
import javax.swing.ButtonGroup;
[code]....
View Replies
View Related
Mar 9, 2015
I'm working on Java-GUI implementation in Ubuntu. Used font-type in the application throughout is "Arial". At earlier stage of application it was the same font-type("Arial"). As the implementation grew the font-type has been changed automatically to another font type. It seems Serif-font type.
Now I could not able to figure out the problem; why it is so.
Note- I used HTML code also for setting font style of Dialog box messages and buttons. This is the only point which I figured out. Can it is ?
View Replies
View Related
Nov 7, 2014
I am copying the xml files from one folder to other folder, in the source folder, i have some files which have some content like "backing File="$IDP_ ROOT/metadata/iPAU-SP-metadata.xml" but while writing to the destination folder.i am replacing the "$IDP_ROOT" with my current working directory. The entire copying of files is for deploying into tomcat server. The copying is done only when server starts for the first time.Problem: If i change the folder name from my root path in my machine after i run the server,the entire process will be stopped because the destination folder files already contains the content which is with existed files names or folder names.
So i want to change it to relative path instead absolute path. What is the best way to do it? Please look at code below:
[ // Getting the current working directory
String currentdir = new File(".").getAbsoluteFile().getParent() + File.separator;
if(currentdir.indexOf("ControlPanel")!=-1){
rootPath=currentdir.substring(0, currentdir.indexOf("ControlPanel"));
}else{
rootPath=currentdir;
[code]....
View Replies
View Related
Aug 25, 2014
i would like from my bean to redirect after an operation is completed to the page faces/test.xhtml?id=2? Is there a way to do this?
View Replies
View Related
Aug 2, 2014
So I created this line class and when I try to create Line object with parameters, I don't know how to pass the parameters properly. It has to return two points, so it should be like [(1,2),(5,12)].I tried different things likeLine l1=new Line(Point p1(1,2),Point p2(5,12)); and similar, but nothing worked.
package line;
import java.awt.Point;
public class Line {
private Point p1;
private Point p2;
[code]...
View Replies
View Related