I want to resize and position a JFrame in Java. How can I achieve that?

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

546 Views

To resize and position JFrame, use the Dimensions class. Here, we have set the bounds for the frame −int width = 500; int height = 400; Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); frame.setBounds((int) size.getWidth() - width, 0, width, height);The following is an example to resize and poisiton a frame −Examplepackage my; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame.setDefaultLookAndFeelDecorated(true);       JFrame frame = new JFrame("Register!");       JLabel label1, label2, label3;       ... Read More

Are there benefits of passing by pointer over passing by reference in C++?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

406 Views

A pointer can receive a null parameter whereas a reference can’t. You can only use pointer if you want to pass “no object”.Explicitly passing by pointer allow us to see the whether the object is passes by reference or value at call site.These are simple example of passing by pointer and passing by reference −Passing by pointerExample Live Demo#include using namespace std; void swap(int* a, int* b) {    int c = *a;    *a= *b;    *b = c; } int main() {    int m =7 , n = 6;    cout

Can we define a method name same as class name in Java?

raja
Updated on 30-Jul-2019 22:30:26

4K+ Views

Yes, It is allowed to define a method with the same name as that of a class. There is no compile-time or runtime error will occur. But this is not recommended as per coding standards in Java. Normally the constructor name and class name always the same in Java.ExampleLive Demopublic class MethodNameTest {    private String str = "Welcome to TutorialsPoint";    public void MethodNameTest() { // Declared method name same as the class name       System.out.println("Both method name and class name are the same");    }    public static void main(String args[]) {       MethodNameTest test ... Read More

How to answer incoming call programmatically in iOS?

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

312 Views

Apple iPhone SDK doesn’t allow this feature. If you really wish to achieve it you can use some private api such as CTCallAnswer(call);This will result in your app store rejection.

HTML DOM li Object

AmitDiwan
Updated on 30-Jul-2019 22:30:26

86 Views

The HTML DOM Li Object in HTML represents the element.SyntaxFollowing is the syntax −Creating a elementvar liObject = document.createElement(“LI”)PropertiesHere, “LiObject” can have the following properties −PropertyDescriptionvalueIt returns/sets the value of the value attribute of a elementExampleLet us see an example for Li value property − Live Demo HTML DOM value    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       border-radius: 10px;    }    ol{ ... Read More

How to use clock() function in C++

Anvi Jain
Updated on 30-Jul-2019 22:30:26

1K+ Views

Here we will see how to use the clock() in C++. This clock() is present in the time.h or ctime header file. Here we will find the elapsed time of a process using this clock() functionTo get the elapsed time, we can get the time using clock() at the beginning, and at the end of the taks, then subtract the values to get the differences. After that we will divide the difference by CLOCK_PER_SEC (Number of clock ticks per second) to get the processor time.Example#include #include using namespace std; void take_enter() {    cout

C++ Program to Implement Caesar Cypher

Anvi Jain
Updated on 30-Jul-2019 22:30:26

19K+ Views

It is a mono-alphabetic cipher wherein each letter of the plaintext is substituted by another letter to form the ciphertext. It is a simplest form of substitution cipher scheme.This cryptosystem is generally referred to as the Shift Cipher. The concept is to replace each alphabet by another alphabet which is ‘shifted’ by some fixed number between 0 and 25.For this type of scheme, both sender and receiver agree on a ‘secret shift number’ for shifting the alphabet. This number which is between 0 and 25 becomes the key of encryption.The name ‘Caesar Cipher’ is occasionally used to describe the Shift ... Read More

How to remove the notification after the particular time in android?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

470 Views

This example demonstrate about How to remove the notification after the particular time in androidStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.os.Handler ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import android.widget.Button ; public class MainActivity extends AppCompatActivity ... Read More

Undefined Behaviour in C and C++

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

202 Views

Here we will see some C and C++ Codes. and try to guess the results. The codes will generate some runtime errors.1. The Divide By Zero error is undefined.Example Code#include using namespace std; int main() {    int x = 10, y = 0;    int z = x / y;    cout

How to change the maximum value of a JSlider in Java?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

285 Views

To change the maximum value of a slider in Java, use the setMaximum() method wherein set the maximum value.Let’s say the following is our slider in Java −JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 100, 55); slider.setMinorTickSpacing(10); slider.setMajorTickSpacing(25); slider.setPaintTicks(true); slider.setPaintLabels(true);Now, set the maximum value −slider.setMaximum(150);The following is an example to change the maximum value of a slidier −Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Frame with Slider");       JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, ... Read More

Advertisements