LogoLogo
v7.0.0
v7.0.0
  • TotalCross Overview
  • TotalCross Javadoc
  • TotalCross Changelog
  • Roadmap
  • Documentation
    • Getting Started
      • First embedded project with TotalCross
    • Components
      • Accordion
      • Aligned Labels
      • Button
      • Check
      • ComboBox
      • Dynamic Scroll
      • Edit
      • Floating Button
      • Gpiod
      • Grid
      • GridContainer
      • Image
      • ImageControl
      • ImageList
      • Label
      • Material Icons
      • Material Window
      • MessageBox
      • Multi Edit
      • Progress Bar
      • Progress Box
      • Radio
      • Radio Group
      • Scroll Container
      • Side Menu
      • Slider
      • Sliding Window
      • Spin List
      • Spinner
      • Switch
      • Tabbed Container
      • Velocimeter
    • APIs
      • API Overview
      • API Rest
      • Asynchronous Task
      • Camera
      • Control
        • Main Window
        • Window
        • Container
      • GPS
      • HTTPS and SSL
      • JSON
      • Maps
        • Maps - Deprecated
        • Static Map
      • Material Design Standards
      • Ninepath
      • Notifications
      • PrinterManager
      • Push Notification Firebase
      • Scanner
      • SOAP
      • Socket
      • SocketServer
      • SQLite Encryption
      • QR Code Generator
      • totalcross.sys
      • Youtube API
    • Creating an Issue
    • Contributing
      • Branch workflow
      • Writing documentation
    • Guides
      • App Architecture
        • Suggested Architecture
        • Why do Design Patterns help with the application's organization?
          • MVC Architecture Pattern
          • Template Pattern
          • Data Persistence: DAO Pattern.
        • Separation of concepts: What is the best way to create UI interfaces?
        • Positioning
          • Manual Positioning
        • Relative Positioning
        • Best practices to improve project maintenance
      • Device Simulator
      • Package your app from scratch
        • TotalCross SDK
        • Environment Variables in IDE
          • Eclipse
          • IntelliJ
        • Deploy your app with a dependecy TC
        • Deploy iOS
          • Using Development certificate to test your apps
      • Understanding TotalCross for Linux ARM
      • Running C++ applications with TotalCross
      • Web Services
    • Miscelaneous
      • Java JDK 8
      • Maven
      • Installing Visual Studio Code
    • FAQ
      • IMEI in Android 10
Powered by GitBook
On this page
  • Overview
  • Source Code
  • Methods
  • References

Was this helpful?

  1. Documentation
  2. Components

ImageControl

Overview

A control that can show an image bigger than its area and that can be dragged using a pen to show the hidden parts.

Note that, by default, events (and dragging) are disabled. You must call setEventsEnabled to allow dragging.

Source Code

Login TCSample
import java.sql.SQLException;

import totalcross.db.sqlite.SQLiteUtil;
import totalcross.io.IOException;
import totalcross.sample.util.Colors;
import totalcross.sql.PreparedStatement;
import totalcross.sql.Statement;
import totalcross.sys.Settings;
import totalcross.sys.Vm;
import totalcross.ui.Button;
import totalcross.ui.Check;
import totalcross.ui.Container;
import totalcross.ui.Edit;
import totalcross.ui.ImageControl;
import totalcross.ui.ScrollContainer;
import totalcross.ui.dialog.MessageBox;
import totalcross.ui.event.ControlEvent;
import totalcross.ui.event.Event;
import totalcross.ui.gfx.Color;
import totalcross.ui.image.Image;
import totalcross.ui.image.ImageException;
import totalcross.util.InvalidDateException;

public class Login extends ScrollContainer {
	private Edit edPass, edLogin;
	private Check ch;
	private Button btLogin, btRegister;
	private ImageControl ic;
    private SQLiteUtil util;
	
	public void initUI(){
		try {
			setBackForeColors(Colors.BACKGROUND, Colors.ON_BACKGROUND);
			ic = new ImageControl(new Image("images/logo.png"));
			ic.scaleToFit = true;
			ic.centerImage = true;
			add(ic, LEFT, TOP+100, FILL, PARENTSIZE+30);
			
			edLogin = new Edit();
			edLogin.caption = "Login";
			//edLogin.setBackColor(Color.RED);
			add(edLogin, CENTER, AFTER+60, PARENTSIZE+90, PREFERRED+30);
			
			edPass = new Edit();
			edPass.caption = "Password";
			//edPass.setBackColor(Color.RED);
			edPass.setMode(Edit.PASSWORD_ALL);
			add(edPass, SAME, AFTER+70, PARENTSIZE+90, PREFERRED+30);
			
			ch = new Check("Remember Me");
			add(ch, LEFT+86, AFTER+100, PARENTSIZE, PREFERRED+30);
			
			btLogin = new Button("Login");
			btLogin.setBackColor(Color.WHITE);
			add(btLogin, CENTER, AFTER+140, PARENTSIZE+80, PREFERRED+60);
			
			btRegister = new Button("Register Now");
			btRegister.transparentBackground = true;
			btRegister.setBorder(BORDER_NONE);
			add(btRegister, CENTER, AFTER, PARENTSIZE+30, PREFERRED+20);
			btRegister.addPressListener(e -> {Vm.exec("url", "http://www.totalcross.com", 0, true);});
			
			//Creating Database
			util = new SQLiteUtil(Settings.appPath,"database.db");
	        Vm.debug(util.fullPath);
			    
	        Statement st = util.con().createStatement();
			st.execute("create table if not exists person (login varchar(20), password varchar(20))");
			st.close();
		
		} catch (IOException | ImageException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void onEvent(Event e){
		try{
			switch(e.type){
				case ControlEvent.PRESSED:
					if(e.target == btLogin){
						doInsert();
					}
			}
		}catch(Exception ee){
			MessageBox.showException(ee, true);
		}
	}
	
	private void doInsert() throws SQLException, InvalidDateException, ImageException {
		if (edLogin.getLength() == 0 || edPass.getLength() == 0){
			MessageBox mb = new MessageBox("Message","Please fill all fields!",new String[]{"Close"});
			mb.setBackForeColors(Color.WHITE, Color.BLACK);
			mb.popup();
		}else {
		// simple example of how you can insert data into SQLite..
			String sql = "insert into person values(?,?)";
			PreparedStatement st = util.con().prepareStatement(sql);
			st.setString(1, edLogin.getText());
			st.setString(2, edPass.getText());
			st.executeUpdate();
			st.close();		
			
			MessageBox mbox = new MessageBox(null,"Data inserted successfully!");
			mbox.setBackForeColors(Color.WHITE, Color.BLACK);
			mbox.popup();
			
		}
	}
}

Methods

Type

Name

Description

Constructor

ImageControl(Image img)

Constructs an ImageControl using the given image.

Constructor

ImageControl()

Constructs with no initial image. You must set the image with the setImage method.

void

setEventsEnabled(boolean enabled)

Pass true to enable dragging and events on the image.

void

setImage(Image img)

Sets the image to the given one. If the image size is different, you must explicitly call setRect again if you want to resize the control.

void

setImage(Image img, boolean resetPositions)

Sets the image to the given one, optionally resetting the image position. If the image size is different, you must explicitly call setRect again if you want to resize the control.

int

getImageHeight()

Returns the image's height; when scaling, returns the scaled height

int

getImageWidth()

Returns the image's width; when scaling, returns the scaled width.

Image

getImage()

Returns the current image assigned to this ImageControl.

void

setBackground(Image img)

Sets the given image as a freezed background of this image control.

boolean

moveTo(int newX, int newY)

Moves to the given coordinates, respecting the current moving policy regarding

References

PreviousImageNextImageList

Last updated 5 years ago

Was this helpful?

Do not forget to create a folder called "images" inside /src/main/resources and save the logopng image inside it [images].

See the for more information.

See the code on

.
Java Docs
Github