Create code-first Java program in JPA/Hibernate

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class App {
public static void main(String[] args) {
System.out.println("Hibernate one to many (Annotation)");
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();

Category cat = new Category("Phone");;
Product iPhone = new Product(cat, "iPhone8");
Product galaxy = new Product(cat, "Galaxy S9");

} ============== import java.util.HashSet; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import static javax.persistence.GenerationType.IDEN…

How to create scrollable ListView with controls above and below in fixed position?

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="" xmlns:tools="" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.philip.MainActivity"> <TextView android:id="@+id/txt" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:text="Happy Independence Day!" android:textAppearance="?android:attr/textAppearanceLarge"/> <Button android:id="@+id/btn" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" a…

Draggable Rectangle in JavaFX

import javafx.application.Application;
import javafx.geometry.Bounds;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class DraggableRectangle extends Application {

private double x = 0;
private double y = 0;
private double sceneX = 0;
private double sceneY = 0;
private Rectangle rect;
public static Pane root;

public void start(Stage primaryStage) throws Exception {
rect = new Rectangle();

rect.setOnMousePressed(e -> {
if (e.getButton() == MouseButton.PRIMARY) {
// Get the current mouse coordinates relative to the scene.
sceneX …

How to display a label with connecting line between two circles?

import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.DoubleBinding;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Point2D;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;

public class CircleWithConnectedLine extends Application {
public static void main(String[] args) {

public void start(Stage primaryStage) throws Exception {
Circle c1 = new Circle(40, 40, 20);
Circle c2 = new Circle(200, 250, 20);
Line line = new Line();
Text text = new Text(60, 60, "");


Pane pane = new Pane();

How to create draggable Circle on mouse Click in JavaFX?

import java.util.Random;
import javafx.application.Application;
import javafx.event.Event;
import javafx.geometry.Point2D;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class GenerateCircleOnClick extends Application {

Random rng = new Random();

public void start(Stage primaryStage) {
Pane pane = new Pane();
pane.setOnMouseClicked(e -> {
Circle c = createDraggableCircle(e.getX(), e.getY(), 25, pane);


primaryStage.setScene(new Scene(pane, 600, 600));;

private Circle createDraggableCircle(double radius, double x, double y, Pane parent) {
Color fill = new Color(rng.nextDouble(), rng.nextDouble(), rng.nextDouble(), 1);
Circle c = new Circle(radius, x, y, fill);
ObjectProperty<Point2D> lo…

How to move the android view by touch drag drop action?

public class MainActivity extends AppCompatActivity implements View.OnTouchListener{ ViewGroup root; Button btn; float offsetX; float offsetY; @Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); root = (ViewGroup)findViewById(; btn = new Button(this); btn.setText("Drag Me!"); btn.setWidth(140); btn.setHeight(70); btn.setOnTouchListener(this); root.addView(btn); } public boolean onTouch(View view, MotionEvent event) { float x = event.getRawX(); float y = event.getRawY(); float maxX = root.getWidth() - view.getWidth(); float maxY = root.getHeight() - view.getHeight(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: offsetX = view.getX() - x; offsetY = view.getY() - y; break; case MotionEvent.ACTION_MOVE: …

How to create a bouncing ball in Android?

import android.content.Context; import; import; import; import; import; import; import android.os.Bundle; import android.view.View; class BouncingBall extends View { public Paint p; private static final int R = 30; private int x, y; private int stepX = 50, stepY = 30; public BouncingBall(Context context) { super(context); p = new Paint(); p.setShader(new RadialGradient(x, y,R, Color.GREEN, Color.BLUE, Shader.TileMode.REPEAT)); } @Overrideprotected void onSizeChanged(int w, int h, int oldW, int oldH) { x = w / 2; y = h / 2; } protected void onDraw(Canvas c) { int w = getWidth(); int h = getHeight(); x += stepX; y += stepY; int maxX = w - R; int maxY = h - R; if (x >= maxX) { x = maxX; stepX *= -1; …