Programming Articles - Page 2653 of 3366

How to set fullscreen mode for Java Swing Application?

Krantik Chavan
Updated on 30-Jul-2019 22:30:26

6K+ Views

To set fullscreen mode for your Java Swing application, use the setFullScreenWindow() method:GraphicsDevice device = graphics.getDefaultScreenDevice(); JFrame frame = new JFrame("Fullscreen"); device.setFullScreenWindow(frame);The following is an example to set fullscreen mode for Java Swing Application:Exampleimport java.awt.Color; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) {       GraphicsEnvironment graphics =       GraphicsEnvironment.getLocalGraphicsEnvironment();       GraphicsDevice device = graphics.getDefaultScreenDevice();       JFrame frame = new JFrame("Fullscreen");       JPanel panel = new JPanel();       JLabel label = new JLabel("", JLabel.CENTER);     ... Read More

How will implement Your Own sizeof in C

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

3K+ Views

To use the sizeof(), we can take the value using a variable x, using &x, it will print the address of it. Now if we increase the value of &x then it may increase in different way. If only one byte is increased, that means it is character, if the increased value is 4, then it is int or float and so on. So by taking the difference between &x + 1 and &x, we can get the size of x.Here we will use macro as the datatype is not defined in the function. And one more thing, we are ... Read More

How will you show memory representation of C variables?

Samual Sam
Updated on 30-Jul-2019 22:30:26

561 Views

Here we will see how to print the memory representation of C variables. Here we will show integers, floats, and pointers.To solve this problem, we have to follow these steps −Get the address and the size of the variableTypecast the address to the character pointer to get byte addressNow loop for the size of the variable and print the value of typecasted pointer.Example#include typedef unsigned char *byte_pointer; //create byte pointer using char* void disp_bytes(byte_pointer ptr, int len) {     //this will take byte pointer, and print memory content    int i;    for (i = 0; i < ... Read More

Make a custom cursor appear when the user moves the mouse over some text in a Java Swing JDialog

Krantik Chavan
Updated on 30-Jul-2019 22:30:26

750 Views

At first set the label on which you want the custom cursor to be visible on hover:JLabel label = new JLabel("Demo text! Hand cursor is visible on hover...");Now, set cursor to be visible as Hand Cursor instead of the default Cursor:label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));The following is an example to make a custom cursor appear when the user moves the mouse over some text:Exampleimport java.awt.Cursor; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; public class SwingDemo extends JFrame {    private void ShowDialog() {       JLabel label = new JLabel("Demo text! Hand cursor is visible on hover...");       label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));   ... Read More

Parameter Passing Techniques in C/C++

Samual Sam
Updated on 30-Jul-2019 22:30:26

6K+ Views

In C we can pass parameters in two different ways. These are call by value, and call by address, In C++, we can get another technique. This is called Call by reference. Let us see the effect of these, and how they work.First we will see call by value. In this technique, the parameters are copied to the function arguments. So if some modifications are done, that will update the copied value, not the actual value.Example#include using namespace std; void my_swap(int x, int y) {    int temp;    temp = x;    x = y;    y = ... Read More

How do you get the font metrics in Java Swing?

Krantik Chavan
Updated on 30-Jul-2019 22:30:26

576 Views

To get the font metrics, use the FontMetrics class:Graphics2D graphics = (Graphics2D) gp.create(); String str = getWidth() + "(Width) x (Height)" + getHeight(); FontMetrics m = graphics.getFontMetrics();Now to display it:int xValue = (getWidth() - m.stringWidth(str)) / 2; int yValue = ((getHeight() - m.getHeight()) / 2) + m.getAscent(); graphics.drawString(str, xValue, yValue);The following is an example to get the font metrics in Java Swing:Exampleimport java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Font Metrics");       ... Read More

Nested functions in C

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

5K+ Views

In some applications, we have seen that some functions are declared inside another function. This is sometimes known as nested function, but actually this is not the nested function. This is called the lexical scoping. Lexical scoping is not valid in C because the compiler is unable to reach correct memory location of inner function.Nested function definitions cannot access local variables of surrounding blocks. They can access only global variables. In C there are two nested scopes the local and the global. So nested function has some limited use. If we want to create nested function like below, it will ... Read More

Implicit return type int in C

Samual Sam
Updated on 30-Jul-2019 22:30:26

486 Views

If some function has no return type, then the return type will be int implicitly. If return type is not present, then it will not generate any error. However, C99 version does not allow return type to be omitted even if it is int.Example#include my_function(int x) {    return x * 2; } main(void) {    printf("Value is: %d", my_function(10)); }OutputValue is: 20

Java Program to create Arrow Button positioning North

Krantik Chavan
Updated on 30-Jul-2019 22:30:26

272 Views

To create Arrow Button at position north, use BasicArrowButton:BasicArrowButton arrow = new BasicArrowButton(BasicArrowButton.NORTH);Above, we have set the arrow to NORTH. Now add it to Panel:panel.add(arrow, BorderLayout.NORTH);The following is an example to create Arrow Button positioning North:Exampleimport java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.plaf.basic.BasicArrowButton; public class SwingDemo extends JPanel {    public SwingDemo() {       setLayout(new BorderLayout());       JPanel panel = new JPanel(new BorderLayout());       add(panel, BorderLayout.EAST);       BasicArrowButton arrow = new BasicArrowButton(BasicArrowButton.NORTH);       panel.add(arrow, BorderLayout.NORTH);    }    public static void main(String[] args) {       JFrame frame = ... Read More

Using range in switch case in C/C++

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

8K+ Views

In C or C++, we have used the switch-case statement. In the switch statement we pass some value, and using different cases, we can check the value. Here we will see that we can use ranges in the case statement.The syntax of using range in Case is like below −case low … highAfter writing case, we have to put lower value, then one space, then three dots, then another space, and the higher value.In the following program, we will see what will be the output for the range based case statement.Example#include main() {    int data[10] = { 5, ... Read More

Advertisements